普通的DropDownList,RadioButtonList数据绑定我知道怎么做,但是数据绑定后,要选中数据库存储的数据项就有点迷糊了。两年没碰DONET了,望各位大侠多多指教,谢谢。

解决方案 »

  1.   

    DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue("..."));
    DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText("..."));RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByValue("..."));
    RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByText("..."));
      

  2.   

    我做的是一个读取的操作。首先我将表中所有的数据取出来,然后赋值给控件,但是赋值完了后,我得选中数据库对应的值才行。 
                       
    //栏目下拉列框数据填充
    this.DropDownList1.DataSource = GetAllTabledata();
    this.DropDownList1.DataTextField = "Cvalue";
    this.DropDownList1.DataValueField = "Cid";
    this.DropDownList1.DataBind();我现在只做到了这一步,怎么选中数据,还得请教各位,感谢。
      

  3.   

    你的绑定是指什么
    DataTextField和DataValueField,还是Items.Add(new ListItem(txt, value))
      

  4.   

    就是普通的DropDownList数据绑定(从A表中将对应的两列数据分别绑定到DropDownList中的DataTextField ,和DataValueField 。然后取出B表对应的值,将B表的值选中,就这么简单。)
      

  5.   


    RadioButtonList也是这样吗? 
      

  6.   

    首先进行数据绑定,然后从数据库中取得一个值(ps:这个值在绑定的数据源中要存在)然后通过如下代码进行选中:
    ...
    string s = "aa";
    this.DropDownList1.Items.FindByText(s).Selected = true;   //如果绑定的是Text值
    this.DropDownList1.Items.FindByValue(s).Selected = true;  //如果绑定的是Value值