DropDownList与RadioButtonList的数据绑定后选中问题。 普通的DropDownList,RadioButtonList数据绑定我知道怎么做,但是数据绑定后,要选中数据库存储的数据项就有点迷糊了。两年没碰DONET了,望各位大侠多多指教,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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("...")); 我做的是一个读取的操作。首先我将表中所有的数据取出来,然后赋值给控件,但是赋值完了后,我得选中数据库对应的值才行。 //栏目下拉列框数据填充this.DropDownList1.DataSource = GetAllTabledata();this.DropDownList1.DataTextField = "Cvalue";this.DropDownList1.DataValueField = "Cid";this.DropDownList1.DataBind();我现在只做到了这一步,怎么选中数据,还得请教各位,感谢。 你的绑定是指什么DataTextField和DataValueField,还是Items.Add(new ListItem(txt, value)) 就是普通的DropDownList数据绑定(从A表中将对应的两列数据分别绑定到DropDownList中的DataTextField ,和DataValueField 。然后取出B表对应的值,将B表的值选中,就这么简单。) RadioButtonList也是这样吗? 首先进行数据绑定,然后从数据库中取得一个值(ps:这个值在绑定的数据源中要存在)然后通过如下代码进行选中:...string s = "aa";this.DropDownList1.Items.FindByText(s).Selected = true; //如果绑定的是Text值this.DropDownList1.Items.FindByValue(s).Selected = true; //如果绑定的是Value值 请教 asp.net项目问题 标准表达式中数据类型不匹配。 当数据库内有null记录时,出错.(急) 新手求一循环方法,50分相送,急急~~~谢谢 文件上传时如何获取客户端的路径而不是服务器端的?? 问个关于ispostback的问题 关于验证空件的小问题1!!!!!!!!!! sql2000的高手进 帮帮我这个菜鸟 asp.net中的datagrid控件问题 讨论下ASP.NET,从客户端获取控件值的问题 分享《个人眼中的面向对编程》
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText("..."));RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByValue("..."));
RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByText("..."));
//栏目下拉列框数据填充
this.DropDownList1.DataSource = GetAllTabledata();
this.DropDownList1.DataTextField = "Cvalue";
this.DropDownList1.DataValueField = "Cid";
this.DropDownList1.DataBind();我现在只做到了这一步,怎么选中数据,还得请教各位,感谢。
DataTextField和DataValueField,还是Items.Add(new ListItem(txt, value))
RadioButtonList也是这样吗?
...
string s = "aa";
this.DropDownList1.Items.FindByText(s).Selected = true; //如果绑定的是Text值
this.DropDownList1.Items.FindByValue(s).Selected = true; //如果绑定的是Value值