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绑定及修改的更多相关文章

  1. 下拉列表框DropDownList绑定Dictionary泛型类

    DropDownList绑定Dictionary泛型类 定义一个Dictionary泛型类 /// <summary>    /// 产品类型    /// </summary> ...

  2. DropdownList绑定的两种方法

    动态绑定方法一:动态绑定数据库中的字段. SqlConnection conn = UtilitySqlClass.OperateDataBase.ReturnConn();string strSQL ...

  3. DropDownList绑定多个字段值

    发觉这个问题还是挺多人问的,简单写几个例子: 假设现有1张表名为:XUDAXIA  , 该表里有2个字段:  NAME , GENDER 达到效果: 将这2个字段绑定到DropDownList的Lis ...

  4. dropdownlist绑定和选中

    最近在使用dropdownlist控件,对于这个控件,目前我知道的会使用两种方式去绑定数据,现在将这两种方式分享给大家: 现在是后台数据绑定 protected void BindCarID() { ...

  5. C# DropDownList绑定添加新数据的几种方法

    第一种:在前台手动绑定(适用于固定不变的数据项) <asp:DropDownList ID="DropDownList1" runat="server"& ...

  6. C# DropDownList绑定添加新数据的三种方法

    一.在前台手动绑定 <asp:DropDownList ID="DropDownList1" runat="server">    <asp: ...

  7. DropDownList绑定数据

    DDLName.DataSource = myRd;DDLName.DataTextField = "name";//要绑定的字段DDLName.DataValueField = ...

  8. C# DropDownList绑定文件夹

    首先创建一个类,类名称为FileControl, /// <summary> /// 获取制定文件夹下面的文件夹 /// </summary> /// <param na ...

  9. ASP.NET - JQuery的.getJSON给Dropdownlist绑定Item

    http://www.cnblogs.com/Mac_Hui/archive/2010/07/27/1785864.html 1.首先建立以个.ashx文件(Generic Handler),在此文件 ...

随机推荐

  1. 阿里云ECS购买优惠码

    今天收到了阿里云给我发的邮件,大意是阿里云推荐码限量开放,可享九折优惠! 于是就点击进去申请了一下 申请的优惠码是:C7IYIS有效期至2015-11-30 23:59:59 首次购买包年包月云服务器 ...

  2. AutoHotKey 使用ADODB读取Excel 报ADODB.Connection 未找到提供程序,可能未提供

    一.系统环境 操作系统:Win7 64位 英文版 Office:     Office 2010 64位/32位 AutoHotKey:AutoHotKey 1.1.26.01 二.问题现象 安装了A ...

  3. Html5-Video标签以及字幕subtitles和captions的区别

    <video id="mainvideo" src="video.mp4" type="video/mp4"controls auto ...

  4. Java 正则表达式的实际应用

    正则表达式最详细-----> | |目录 1匹配验证-验证Email是否正确 2在字符串中查询字符或者字符串 3常用正则表达式 4正则表达式语法 1匹配验证-验证Email是否正确 public ...

  5. (转)用事实说话,成熟的ORM性能不是瓶颈,灵活性不是问题:EF5.0、PDF.NET5.0、Dapper原理分析与测试手记

    原文地址:http://www.cnblogs.com/bluedoctor/p/3378683.html [本文篇幅较长,可以通过目录查看您感兴趣的内容,或者下载格式良好的PDF版本文件查看] 目录 ...

  6. 正确理解WPF中的TemplatedParent (转贴)

    http://blog.csdn.net/idebian/article/details/8761388 (注:Logical Tree中文称为逻辑树,Visual Tree中文称为可视化树或者视觉树 ...

  7. poj3274 Gold Balanced Lineup(HASH)

    Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been abl ...

  8. android 仿QQ气泡聊天界面

    1.现在的QQ,微信等一些APP的聊天界面都是气泡聊天界面,左边是接收到的消息,右边是发送的消息, 这个效果其实就是一个ListView在加载它的Item的时候,分别用了不同的布局xml文件. 2.效 ...

  9. Sharepoint2013搜索学习笔记之自定义查询规则(十)

    自定义查询规则,可以根据搜索的关键字将指定的一个或一堆搜索结果提升到第一的位置,如我搜索周杰伦,可以指定搜索最靠前的结果是sharepoint网站内周杰伦的视频如下图: 第一步,进入管理中心,点击管理 ...

  10. 微软日志工厂 Microsoft.Extensions.Logging 中增加 log4net 的日志输出

    前提: 需要nuget   Microsoft.Extensions.Logging.Log4Net.AspNetCore   2.2.6: 描述:解决 .net core 微软日志工厂 Micros ...