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();//这里用Hashtableht.Add("字段名",DropDownListID.SelectedItem.Text.ToString());//保存选项Textht.Add("字段名",DropDownListID.SelectedItem.Value.ToString());//保存选项Value2、选项值由数据库绑定到DropDownList:首先DropDownListID.ClearSelection();//清除选项DropDownListID.Items.FindByText(dr["字段名"].ToString()).Selected = true;//选项TextDropDownListID.Items.FindByValue(dr["字段名"].ToString()).Selected = true;//选项Value二、RadioButtonList:1、选项值保存到数据库(同DropDownList):Hashtable ht=new Hashtable();//这里用Hashtableht.Add("字段名",RadioButtonListID.SelectedItem.Text.ToString());//保存选项Textht.Add("字段名",RadioButtonListID.SelectedItem.Value.ToString());//保存选项Value2、选项值由数据库绑定到RadioButtonListstring SelectItem = dr["字段名"].ToString();//将数据库中的选项值从DataRow中读出赋给变量SelectItemfor (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、选项值由数据库绑定到CheckBoxListstring 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),在此文件 ...
随机推荐
- 在页面完成读取EXCEL
protected void btnUpload_Click(object sender, EventArgs e) { if (Page.IsValid) { string sFILENAME = ...
- ADO.NET连接池
池:理解为一堆集合,一堆数组,一堆对象ado.net连接池,连接字符串注明Pooling=false关闭连接池 web应用是肯定要启动连接池的,因为默认启动,可以不用管,知道这么一回事就OK了当启动连 ...
- win10 Kinect2 Visualstudio2015 opencv3环境搭建
1.下载kinect SDK ( Kinect for Windows SDK 2.0 ): https://www.microsoft.com/en-us/download/details.asp ...
- Win10 DHCP和Static IP 切换
创建两个.bat文件,分别命名为static.bat和dhcp.bat static.bat文件写入 netsh interface ip set address "Wi-Fi" ...
- Python pandas.DataFrame调整列顺序及修改index名
1. 从字典创建DataFrame >>> import pandas >>> dict_a = {'],'mark_date':['2017-03-07','20 ...
- 性能优化之_android布局优化
优化布局的的原则就是减少创建的对象的数量,setContentView话费onCreate到onResume中的大概99%的时间1.使用Relativelayout而不是LinearLayout,Li ...
- Django--form生成select标签
需求 Django--form表单中的select生成方法,如果select中的选项不固定,需要怎么操作. 速查 1.固定select选项 forms 1 2 3 class 表单类名称(forms. ...
- python3--列表生成式
# Auther: Aaron Fan # 原始的写法:a = []for i in range(10): a.append(i*2)print(a) # 用列表生成式完成上面的写法:a = [i*2 ...
- ServletContext作用功能详解.RP
ServletContext ServletContext,是一个全局的储存信息的空间,服务器开始,其就存在,服务器关闭,其才释放.request,一个用户可有多个:session,一个用户一个:而s ...
- Java web 中的HttpServletRequest对象
一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...