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),在此文件 ...
随机推荐
- SSH隧道技术简介
本文的受众如果你遇到了以下问题,那么你应该阅读这篇文章 我听说过这种技术,我对它很感兴趣 我想在家里访问我在公司的机器(写程序,查数据,下电影). 公司为了防止我们用XX软件封锁了它的端口或者服务器地 ...
- Angular25 组件的生命周期钩子
1 生命周期钩子概述 组件共有9个生命周期钩子 1.1 生命周期的执行顺序 技巧01:测试时父组件传递对子组件的输入属性进行初始化操作 import { Component, Input, Simpl ...
- rosbag数据记录及转换图片、视频
博客转载自: https://blog.csdn.net/u012706484/article/details/78495896 rosbag常见的使用参数和配置 1.查看.bag中包含的信息 : r ...
- Hyperledger Fabric Orderer节点启动
Orderer 节点启动通过 orderer 包下的 main() 方法实现,会进一步调用到 orderer/common/server 包中的 Main() 方法. 核心代码如下所示. // Mai ...
- c语言实战 BJT时间转化位UTC时间
题目是这样的: 题目内容: UTC是世界协调时,BJT是北京时间,UTC时间相当于BJT减去8.现在,你的程序要读入一个整数,表示BJT的时和分.整数的个位和十位表示分,百位和千位表示小时.如果小时小 ...
- SQL将表中某一类型的一列拼接成一行
SELECT TypeName ,(SELECT ','+ UserName FROM [ContainerMembers] t WHERE TypeName= aa.TypeName FOR XML ...
- Django-Web框架之创建项目和应用
Django我们是基于python3来演示的.首先我们来安装一下django框架.使用pip3 install django安装的是最新的版本: 我们在pycharm中创建django工程.如图所示: ...
- The Three Models of ASP.NET MVC Apps
12 June 2012 by Dino Esposito by Dino Esposito We've inherited from the original MVC pattern a ra ...
- Zynq 在Ubuntu上搭建编译环境
http://bbs.elecfans.com/jishu_487981_1_1.html 以下操作均在root用户下完成1,下载交叉编译器在ubuntu里下载arm-2010.09-62-arm-x ...
- 见过最好的mybatis学习网站
http://blog.csdn.net/techbirds_bao/article/details/9233599/