您的位置:程序门 -> .net技术 -> c#



dropdownlist取值问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


dropdownlist取值问题
发表于:2007-01-11 09:51:11 楼主
在page_load里在if(!ispostback)里绑定了下拉框,在他的selectedindexchanged事件里取值,假如下拉框绑定了xj,zy,aa,bb这四个值,为什么点击aa的时候绑定的总是zy的值?点击xj就好好的。
发表于:2007-01-11 09:54:161楼 得分:0
看看你是怎么绑的dropdownlist,是不是selectedvalue值措位了
发表于:2007-01-11 10:01:322楼 得分:0
是不是selectindex值没变?你设个int   保存index
发表于:2007-01-11 10:05:323楼 得分:0
dropdownlist的使用你搞混淆了!  
只需要在!this.ispostback   中给dropdownlist添加ang
发表于:2007-01-11 10:07:574楼 得分:0
dropdownlist的使用你搞混淆了!  
只需要在!this.ispostback   中给dropdownlist添加一次就行了,
没有必要在用selectedindexchanged
selectedindexchanged主要是用来触发其他的控件的
用在dropdownlist自己的这种写法不是很合理
发表于:2007-01-11 10:11:035楼 得分:0
触发dropdownlist,后还要依据此selecteditem的值把其相关的内容还要帮定到listbox中的
发表于:2007-01-11 10:15:356楼 得分:0
代码写出来。我帮你调
发表于:2007-01-11 10:17:037楼 得分:0
protected   void   page_load(object   sender,   eventargs   e)
        {
                if   (!ispostback)
                {
                        //绑定自己有权限查看的人员
                        if   ((string)session[ "username "]   ==   null)//原为!=
                        {
                                response.redirect( "login.aspx ");
                        }
                        string   sr   =   (session[ "组织id "].tostring()).substring(0,   2).tolower();
                        if   (sr   !=   "jy ")
                        {
                                response.redirect( "pageerror.aspx ");
                        }
                        string   sql   =   "select   *   from   tbluser   where   组织id   like   '% "   +   session[ "组织id "].tostring()   +   "% ' ";
                        db   =   new   database();
                        ds   =   new   dataset();
                        ds   =   db.getdatafromdb(sql);
                        this.droppeople.datasource   =   ds;
                        this.droppeople.datavaluefield   =   "工号 ";
                        this.droppeople.datatextfield   =   "姓名 ";
                        this.droppeople.databind();
                        this.droppeople.items.add(new   listitem( "请选择 ",   "0 "));
                        this.droppeople.selectedindex   =   this.droppeople.items.count   -   1;
                        ds.clear();

                }
        }
        protected   void   droppeople_selectedindexchanged(object   sender,   eventargs   e)
        {
                //选择用户名绑定相应的权限
                if   (this.droppeople.selectedvalue   !=   "0 ")
                {
                        int   a   =   this.droppeople.selectedindex;
                        //提出以有的权限
                        string   sql   =   "select   *   from   tblpurview   where   用户姓名= ' "   +   this.droppeople.selecteditem   .text   .trim   ()   +   " ' ";//and   部门= '2 ' ";
                        db   =   new   database();
                        ds   =   new   dataset();
                        ds   =   db.getdatafromdb(sql);
                        if   (ds   !=   null)
                        {
                                this.listnew.datasource   =   ds;
                                this.listnew.datavaluefield   =   "用户权限url ";
                                this.listnew.datatextfield   =   "用户权限页名 ";
                                this.listnew.databind();
                                ds.clear();
                        }
                        //内部的看所有权限
                        string   allsql   =   "select   *   from   tbltree   where   url   not   in   (select   用户权限url     from   tblpurview   where   用户姓名= ' "   +   this.droppeople.selecteditem.text   +   " ')     and   子级   is   not   null   order   by   所属公司,父级 ";
                        db   =   new   database();
                        ds   =   new   dataset();
                        ds   =   db.getdatafromdb(allsql);
                        this.listpur.datasource   =   ds;
                        this.listpur.datavaluefield   =   "url ";
                        this.listpur.datatextfield   =   "名称 ";
                        this.listpur.databind();

                }
        }
发表于:2007-01-11 11:18:358楼 得分:0
protected   void   droppeople_selectedindexchanged(object   sender,   eventargs   e)
        {
string   aaa=this.droppeople.selecteditem   .text   .trim   ()  
droppeople.dispose();
                //选择用户名绑定相应的权限
                if   (this.droppeople.selectedvalue   !=   "0 ")
                {
                        int   a   =   this.droppeople.selectedindex;
                        //提出以有的权限
                        string   sql   =   "select   *   from   tblpurview   where   用户姓名= ' "   +   aaa   +   " ' ";//and   部门= '2 ' ";


快速检索

最新资讯
热门点击