DropDownList绑定及修改
http://www.cnblogs.com/hulang/archive/2010/12/29/1920662.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
一、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 ; } } } ================================================= 1.把数据绑定到CheckBoxList中 protected void Page_Load( object sender, EventArgs e) { if (!Page.IsPostBack) { SqlConnection con = GetDBCon.GetCon(); con.Open(); SqlDataAdapter sda = new SqlDataAdapter( "select * from admin" , con); DataSet ds = new DataSet(); sda.Fill(ds, "admin" ); this .CheckBoxList1.DataSource = ds.Tables[0]; this .CheckBoxList1.DataTextField = "username" ; //绑定的字段名 this .CheckBoxList1.DataValueField = "userid" ; //绑定的值 this .CheckBoxList1.DataBind(); } } 2.循环读取出来 protected void CheckBoxList1_SelectedIndexChanged( object sender, EventArgs e) { this .Lab2.Text = "" ; for ( int i = 0; i < CheckBoxList1.Items.Count; i++) { if ( this .CheckBoxList1.Items[i].Selected) { this .Lab2.Text = this .Lab2.Text+CheckBoxList1.Items[i].Text+ "." ; } } } |
DropDownList绑定及修改的更多相关文章
- 下拉列表框DropDownList绑定Dictionary泛型类
DropDownList绑定Dictionary泛型类 定义一个Dictionary泛型类 /// <summary> /// 产品类型 /// </summary> ...
- DropdownList绑定的两种方法
动态绑定方法一:动态绑定数据库中的字段. SqlConnection conn = UtilitySqlClass.OperateDataBase.ReturnConn();string strSQL ...
- DropDownList绑定多个字段值
发觉这个问题还是挺多人问的,简单写几个例子: 假设现有1张表名为:XUDAXIA , 该表里有2个字段: NAME , GENDER 达到效果: 将这2个字段绑定到DropDownList的Lis ...
- dropdownlist绑定和选中
最近在使用dropdownlist控件,对于这个控件,目前我知道的会使用两种方式去绑定数据,现在将这两种方式分享给大家: 现在是后台数据绑定 protected void BindCarID() { ...
- C# DropDownList绑定添加新数据的几种方法
第一种:在前台手动绑定(适用于固定不变的数据项) <asp:DropDownList ID="DropDownList1" runat="server"& ...
- C# DropDownList绑定添加新数据的三种方法
一.在前台手动绑定 <asp:DropDownList ID="DropDownList1" runat="server"> <asp: ...
- DropDownList绑定数据
DDLName.DataSource = myRd;DDLName.DataTextField = "name";//要绑定的字段DDLName.DataValueField = ...
- C# DropDownList绑定文件夹
首先创建一个类,类名称为FileControl, /// <summary> /// 获取制定文件夹下面的文件夹 /// </summary> /// <param na ...
- ASP.NET - JQuery的.getJSON给Dropdownlist绑定Item
http://www.cnblogs.com/Mac_Hui/archive/2010/07/27/1785864.html 1.首先建立以个.ashx文件(Generic Handler),在此文件 ...
随机推荐
- iOS与HTML5交互方法总结(修正)
摘要 看了不少别人写的博客或者论坛,关于iOS与HTML5交互方法大概主要有5种方式: 1. 利用WKWebView进行交互(系统API) 2. 利用UIWebView进行交互(系统API) 3. 苹 ...
- SqlServer------范式小结
说明:大多数初学者对于关系数据库中的范式很是头疼,我本人也是,所以今天又看了视频,总结了一下内容,尽量语言通俗易懂,少用专业术语以及概念. 首先要理解几个键值. 超键:在关系模式中,能唯一标识元组的属 ...
- suse10配置SSH无密码登录的方法
RSH配置(集群中的每台机器执行以下操作) 1.因SUSE LINUX不自带RSH-SERVER服务,所以首先要去从www.rpmfind.net 下载rsh-server服务的RPM包. 然后切换到 ...
- 多重if else和switch case的区别
int main(void) { int id; scanf_s("%d",&id); switch(id) { case 2: printf("John\n&q ...
- Part5核心初始化_lesson2---设置svc模式
我们的Linux系统以及bootloader是工作在SVC模式!!怎么把处理器设置为SVC模式呢? CPSR寄存器或者SPSR寄存器最低5位可以设置模式,把该5位设置为0b10011, start.s ...
- Linux下的strerror是否线程安全?
下列是glibc-2.14中的源代码: 点击(此处)折叠或打开 char * strerror (errnum) int errnum; { char *ret = __strerror_r (err ...
- (转)ASP.NET MVC4+EasyUI+EntityFrameWork权限管理系统——数据库的设计(一)
原文地址:http://www.cnblogs.com/cmsdn/p/3371576.html 快一年没写博客了,这段时间感觉好迷茫,写点博客,记录一下自己的成长过程,希望对大家也有帮助 先上图 一 ...
- 【Head First Java 读书笔记】(五)编写程序
第五章 编写程序 伪码:伪码能帮你专注于逻辑而不需要顾虑到程序语法 测试码:测试用的程序代码 真实码:实际代码 伪码 伪码是介于真正的java程序与正常英语之间的一种语言.伪码大致包括3部分:实例变量 ...
- Java集合类总结 (五)
集合框架 为了避免进行不必要的随机访问操作,Java引入了一种标签接口RandomAccess, 这个接口没有任何方法,只是一个标签,用来标记一个集合是否应该进行随机访问操作: if (c insta ...
- JAVA8 Lambda 表达式使用心得
List<HashMap> 指定数据求和: List<HashMap> kk = new ArrayList<>(); Map mmm = new H ...