关于DropDownList、RadioButtonList和CheckBoxList绑定
2008-07-12 23:32
447 查看
2008-05-23 11:00
关于DropDownList、RadioButtonList和CheckBoxList绑定 一、DropDownList: 1、选项值保存到数据库: Hashtable ht=new Hashtable();//这里用Hashtable ht.Add("字段名",DropDownListID.SelectedItem.Text.ToString());//保存选项Text ht.Add("字段名",DropDownListID.SelectedItem.Value.ToString());//保存选项Value 2、选项值由数据库绑定到DropDownList: 首先DropDownListID.ClearSelection();//清除选项 DropDownListID.Items.FindByText(dr["字段名"].ToString()).Selected = true;//选项Text DropDownListID.Items.FindByValue(dr["字段名"].ToString()).Selected = true;//选项Value 二、RadioButtonList: 1、选项值保存到数据库(同DropDownList): Hashtable ht=new Hashtable();//这里用Hashtable ht.Add("字段名",RadioButtonListID.SelectedItem.Text.ToString());//保存选项Text ht.Add("字段名",RadioButtonListID.SelectedItem.Value.ToString());//保存选项Value 2、选项值由数据库绑定到RadioButtonList string SelectItem = dr["字段名"].ToString();//将数据库中的选项值从DataRow中读出赋给变量SelectItem for (int i = 0; i < RadioButtonListID.Items.Count; i++) {//用for循环判断那项被选种 if (RadioButtonListID.Items[i].Text == SelectItem)RadioButtonListID.Items[i].Selected = true; } 三、CheckBoxList: 1、选项值保存到数据库 string SelectItem = "";//声明一个变量来接受选项 for (int i = 0; i < CheckBoxListID.Items.Count; i++) {//用for循环将所有选项用","隔开连接起来 if (CheckBoxListID.Items[i].Selected) { SelectItem = SelectItem + CheckBoxListID.Items[i].Value + ",";//选项后加","隔开 } } ht.Add("字段名",SelectItem.ToString()); 2、选项值由数据库绑定到CheckBoxList string SelectItem = dr["字段名"].ToString(); string[] arrStr = SelectItem.Split(',');//字段是以","隔开 foreach (string str in arrStr) { for (int i = 0; i <CheckBoxListID.Items.Count; i++) { if (this.CheckBoxListID.Items[i].Value == str) { this.CheckBoxListID.Items[i].Selected = true; } |
相关文章推荐
- DataSet绑定ListBox、DropDownList、RadioButtonList、CheckBoxList控件
- .NET常用控件绑定(DropDownList、RadioButtonList、CheckBoxList、ListBox、BulletedList)
- ASP.NET中 RadioButtonList(单选按钮组),CheckBoxList(复选框组),DropDownList(下拉框),ListBox(列表框),BulletedList(无序列表)的使用前台绑定
- ListBox,CheckBoxList,DropDownList,RadioButtonList的常见数据绑定
- DataSet绑定ListBox、DropDownList、RadioButtonList、CheckBoxList控件
- 关于RadioButtonList,CheckBoxList,DropDownList的Selected Bind
- jquery.validator 验证CheckBoxList,RadioButtonList,DropDownList
- .net 获取checkBoxList 选中的值|radiobuttonlist|dropdownlist
- 选择checkBoxList|radiobuttonlist|dropdownlist 的的值
- Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中
- ListBox,CheckBoxList,DropDownList,RadioButtonList的常见用法
- 选择checkBoxList|radiobuttonlist|dropdownlist 的的值
- JQuery中对服务器控件 DropdownList, RadioButtonList, CheckboxList的操作总结
- 使用复杂绑定完成 CheckBoxList 和 RadioButtonList 控件的绑定
- 关于CheckBoxList和RadioButtonList的几个问题
- c#枚举类型在web控件CheckBoxList,RadioButtonList,DropDownList中的应用
- Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中
- JQuery 对服务器控件 DropdownList, RadioButtonList, CheckboxList的操作总结
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法