ListBox,CheckBoxList,DropDownList,RadioButtonList的常见数据绑定
void way1()
{
DropDownList1.Items.Add("c#");
DropDownList1.Items.Add("vb");
DropDownList1.Items.Add("c");
DropDownList1.Items.Add("java");
ListBox1.Items.Add("c#");
ListBox1.Items.Add("VB");
ListBox1.Items.Add("C++");
ListBox1.Items.Add("JAVA"); CheckBoxList1.Items.Add("c#");
CheckBoxList1.Items.Add("VB");
CheckBoxList1.Items.Add("javascript");
CheckBoxList1.Items.Add("php");
RadioButtonList1.Items.Add("asp");
RadioButtonList1.Items.Add("php");
RadioButtonList1.Items.Add("jsp");
RadioButtonList1.Items.Add("ajax");
}
哈斯表法:
void way2()
{
Hashtable ht=new Hashtable();
ht.Add("","c#");
ht.Add("","C++");
ht.Add("","php");
ht.Add("","CGI");
this.DropDownList2.DataSource=ht;
DropDownList2.DataTextField="Value";
DropDownList2.DataValueField="Key";
DropDownList2.DataBind();
this.ListBox2.DataSource=ht;
ListBox2.DataTextField="value";
ListBox2.DataValueField="key";
ListBox2.DataBind();
this.CheckBoxList2.DataSource=ht;
CheckBoxList2.DataTextField="value";
CheckBoxList2.DataValueField="key";
CheckBoxList2.DataBind();
this.RadioButtonList2.DataSource=ht;
RadioButtonList2.DataTextField="value";
RadioButtonList2.DataValueField="key";
RadioButtonList2.DataBind();
}
SortedList方法:
void way3()
{
SortedList s1=new SortedList();
s1.Add("","haha");
s1.Add("","hehe");
s1.Add("","xixi");
s1.Add("","heihei");
this.DropDownList3.DataSource=s1;
DropDownList3.DataTextField="value";
DropDownList3.DataValueField="key";
DropDownList3.DataBind();
}
用数据对象dataread方法:
void way4()
{
OleDbConnection cn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("sailing.mdb")+";Persist Security Info=False");
cn.Open();
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=cn;
cmd.CommandText="select RoleName,RoleID from Role";
OleDbDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
ListItem li=new ListItem(dr[].ToString(),dr[].ToString());
this.ListBox4.Items.Add(li);
}
dr.Close();
cn.Close();
}
用数据集法:
OleDbConnection cn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("sailing.mdb")+";Persist Security Info=False");
cn.Open();
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=cn;
cmd.CommandText="select RoleName,RoleID from Role";
OleDbDataAdapter adp=new OleDbDataAdapter(cmd);
DataSet ds=new DataSet();
adp.Fill(ds); this.CheckBoxList4.DataSource=ds.Tables[];
this.CheckBoxList4.DataTextField=ds.Tables[].Columns[].ToString();
this.CheckBoxList4.DataValueField=ds.Tables[].Columns[].ToString();
this.CheckBoxList4.DataBind(); 还有一种数组法: <%@ Page Language="C#" AutoEventWireup="True" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
ArrayList array=new ArrayList();
array.Add("Windows");
array.Add("Linux");
array.Add("unix");
CheckBox_1.DataSource=array;
CheckBox_1.DataBind();
RadioList_1.DataSource=array;
RadioList_1.DataBind();
}
</Script>
<form id="Form_1" runat="server">
<ASP:checkboxList ID="CheckBox_1" runat="server"/>
<input id="Button_1" type="Button" value="CheckButton" runat="server"/>
<asp:radiobuttonlist ID="RadioList_1" runat="server"/>
<input id="Button_2" type="Button" value="RadioButton" runat="server"/>
</form>
ListBox,CheckBoxList,DropDownList,RadioButtonList的常见数据绑定的更多相关文章
- js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)
js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等) 欢迎访问原稿:http://hi.baidu.com/2wixia ...
- 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定
aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...
- c#listbox使用详解和常见问题解决
关于ListBox ListBox是WinForm中的 列表 控件,它提供了一个项目列表(一组数据项),用户可以选择一个或者多个条目,当列表项目过多时,ListBox会自动添加滚动条,使用户可以滚动查 ...
- Web控件文本框Reset的功能
在前一篇中<怎样实现Web控件文本框Reset的功能>http://www.cnblogs.com/insus/p/4120889.html Insus.NET只实现了文本框的功能.单个或 ...
- Farseer.net轻量级开源框架 中级篇:数据绑定
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: DbFactory数据工厂 下一篇:Farseer.net轻量级开源框架 中级篇: ...
- ASP.NET数据绑定
数据绑定是ASP.NET提供的另一种访问数据库的方法.与ADO.NET数据库访问技术不同的是:数据绑定技术可以让程序员不关注数据库连接.数据库命令以及如何格式化这些数据以显示在页面上等环节,而是直接把 ...
- ASP.NET数据绑定控件
数据绑定控件简介 数据绑定分为:数据源 和 数据绑定控件 两部分,数据绑定控件通过数据源来获得数据,通过数据源来隔离数据提供者和数据使用者,数据源有:SqlDataSource,AccessDataS ...
- ASP.NET数据绑定控件简介
•数据绑定分为数据源和数据绑定控件两部分(①数据绑定控件通过数据源获取和修改数据②数据绑定控件通过数据源隔离数据提供者和数据使用者)数据绑定控件→数据源→数据库•数据源:SqlDataSource(连 ...
- ASP.NET 数据绑定到列表控件
<div> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> ...
随机推荐
- Mac开发快速入门
初次接触mac开发,发现国内相关资料少得可怜,于是写下这篇文章,作为学习记录.Mac应用开发也是使用Objective-C进行开发的,所以从iOS转Mac并不困难,很多东西都一样. 本文以一个登录界面 ...
- 怎样安装CentOS 6.6之三:磁盘分区的划分和修改
安装 CentOS(或Linux)系统,最难的就是磁盘分区.磁盘分区需要根据自己的实际使用需要来规划,以达到最优的效果. 工具/原料 CentOS 6.6 安装包 VMware 虚拟机 一.划分方 ...
- 1、css选择器
一.CSS rgb颜色对照表:https://www.114la.com/other/rgb.htm 1.在标签上设置style属性 <!DOCTYPE html> <html la ...
- python---socket与socketserver
1.socket的方socket.getaddrinfo(host, port, family=0, type=0, proto=0, flags=0) #获取要连接的对端主机地址sk.bind(ad ...
- bootstrap的tab中,echarts 图表宽度设为100%之后,会出现图表宽带变为100px的情况。只有第一个正常
1.原因 echarts官方解释是 Tip: 有时候图表会放在多个标签页里,那些初始隐藏的标签在初始化图表的时候因为获取不到容器的实际高宽,可能会绘制失败,因此在切换到该标签页时需要手动调用resiz ...
- 利用ant 和 Junit 生成测试报告
我们除了使用java来直接运行junit之外,我们还可以使用junit提供的junit task与ant结合来运行. 涉及的几个主要的ant task如下: <junit>,定义一个jun ...
- java 大数详细讲解
介绍 java中用于操作大叔的类主要有俩种 第一个是BigInteger,代表大整数.第二个是BigDecimal,代表大浮点数.两种类的操作方法类似,所以我们只讲解BigInterger的用法 基本 ...
- [Xcode 实际操作]二、视图与手势-(5)给图像视图添加圆角效果
目录:[Swift]Xcode实际操作 本文将演示给矩形图片添加圆角效果 import UIKit class ViewController: UIViewController { override ...
- c++的substr()函数
substr()函数注意:string str =“Hello”: substr(0,4)=“Hell”,0是起始位置,4是要复制的长度,strlen函数输出的是除了结束符"\0" ...
- Tyvj1474 打鼹鼠
Description 在这个“打鼹鼠”的游戏中,鼹鼠会不时地从洞中钻出来,不过不会从洞口钻进去(鼹鼠真胆大……).洞口都在一个大小为n(n<=1024)的正方形中.这个正方形在一个平面直角坐标 ...