一、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;
}
}
}
分享到:
相关推荐
NULL 博文链接:https://walleyekneel.iteye.com/blog/1021557
数据源 数据绑定分为数据源和数据绑定控件两部分,数据绑定控件通过数据源来获得数据,通过数据源来隔离数据提供...数据绑定控件有列表数据绑定控件(DropDownList、RadioButtonList、ListBox、CheckBoxList、BulletedL
0485 如何使用CheckBoxList服务器控件 277 0486 使用RadioButtonList服务器控件巧用单项选择 278 0487 使用BulletedList控件显示项目符号和编号 279 0488 如何使用HiddenField控件 280 0489 如何使用...
54.如何使用CheckBox和CheckBoxList控件(CheckBoxList示例) 55.如何使用RadioButton和RadioButtonList控件(RadioButton示例) 55.如何使用RadioButton和RadioButtonList控件RadioButtonList示例) 56.如何使用Panel...
3.1.4 CheckBOX和CheckBoxList控件应用 3.1.5 RadioButton和RadioButtonList控件应用 3.2 ASP.NET 2.0新增控件 3.2.1 BulletedList控件的应用 3.2.2 Substitution控件的应用 3.2.3 Wizard控件的应用 3.2.4 ...
8.4 模板和数据绑定表达式 241 8.4.1 使用模板 241 8.4.2 使用数据绑定表达式 244 8.4.3 使用两种数据绑定表达式 247 8.5 SQL Server 2005 Express 概述 248 8.5.1 SQL Server Express 特性 248 8.5.2 SQL Server ...
如何使用CheckBox和CheckBoxList控件(CheckBoxList示例) 55.如何使用RadioButton和RadioButtonList控件(RadioButton示例) 55.如何使用RadioButton和RadioButtonList控件RadioButtonList示例) 56.如何...
8.4 模板和数据绑定表达式272 8.4.1 使用模板272 8.4.2 使用数据绑定表达式275 8.4.3 使用双向数据绑定表达式278 8.5 sql server 2008 express概述280 8.5.1 sql server express 特性280 8.5.2 sql server 2008 ...
///DataBindCheckBoxList()CheckBoxList控件绑定 ///ElseIpAddr()调用此方法 返回当前登录的省市IP地址 ///ElseDataTimeIng()返回本地电脑的当前日期的年月日时分秒 动态的显示 JS实现 ///ElsePageLoad()页面...
///DataBindCheckBoxList()CheckBoxList控件绑定 ///ElseIpAddr()调用此方法 返回当前登录的省市IP地址 ///ElseDataTimeIng()返回本地电脑的当前日期的年月日时分秒 动态的显示 JS实现 ///ElsePageLoad()...
///DataBindCheckBoxList()CheckBoxList控件绑定 ///ElseIpAddr()调用此方法 返回当前登录的省市IP地址 ///ElseDataTimeIng()返回本地电脑的当前日期的年月日时分秒 动态的显示 JS实现 ///ElsePageLoad()页面...
///DataBindCheckBoxList()CheckBoxList控件绑定 ///ElseIpAddr()调用此方法 返回当前登录的省市IP地址 ///ElseDataTimeIng()返回本地电脑的当前日期的年月日时分秒 动态的显示 JS实现 ///ElsePageLoad()...
4.2.3CheckBox和CheckBoxList控件 4.2.4RadioButton和RadioButtonList控件 4.2.51mage控件和ImageButton控件 4.2.6HyperLink和LinkButton控件 4.2.7DropDownList和ListBox控件 4.2.8Panel控件 4.2.9TextBox控件 ...
5.6 复选框控件和复选组控件(CheckBox 和CheckBoxList) 5.6.1 复选框控件(CheckBox) 5.6.2 复选组控件(CheckBoxList) 5.7 列表控件(DropDownList,ListBox 和BulletedList) 5.7.1 DropDownList 列表控件 ...
4.2.3 CheckBox和CheckBoxList控件 4.2.4 RadioButton和RadioButtonList控件 4.2.5 Image控件和ImageButton控件 4.2.6 HyperLink和LinkButton控件 4.2.7 DropDownList和ListBox控件 4.2.8 Panel...
本书全面介绍了ASP.NET各种编程技能和2.0版中的巨大变化,并详细阐述了2.0版中的每个新特性。...5.13 CheckBoxList服务器控件139 5.14 RadioButton服务器控件141 5.15 RadioButtonList服务器控件143 5.16 ...
5.6 复选框控件和复选组控件(CheckBox和CheckBoxList) 5.6.1 复选框控件(CheckBox) 5.6.2 复选组控件(CheckBoxList) 5.7 列表控件(DropDownList,ListBox和BulletedList) 5.7.1 DropDownList列表控件 5.7.2 ...
5.6 复选框控件和复选组控件(CheckBox和CheckBoxList) 5.6.1 复选框控件(CheckBox) 5.6.2 复选组控件(CheckBoxList) 5.7 列表控件(DropDownList,ListBox和BulletedList) 5.7.1 DropDownList列表控件 5.7.2 ...
5.6 复选框控件和复选组控件(CheckBox和CheckBoxList) 5.6.1 复选框控件(CheckBox) 5.6.2 复选组控件(CheckBoxList) 5.7 列表控件(DropDownList,ListBox和BulletedList) 5.7.1 DropDownList列表控件 5.7.2 ...
5.6 复选框控件和复选组控件(CheckBox和CheckBoxList) 5.6.1 复选框控件(CheckBox) 5.6.2 复选组控件(CheckBoxList) 5.7 列表控件(DropDownList,ListBox和BulletedList) 5.7.1 DropDownList列表控件 5.7.2 ...