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> ...
随机推荐
- javaScrpit中NaN的秘密
NaN,不是一个数字,是一种特殊的值来代表不可表示的值,使用typeof或其他任何与之比较的处理方式,‘NaN’则会引起一些混乱, 一些操作会导致NaN值的产生.这里有些例子: Math.sqrt(- ...
- C++之remove和remove_if
一.Remove()函数 remove(beg,end,const T& value) //移除区间{beg,end)中每一个“与value相等”的元素: remove只是通过迭代器的指针向前 ...
- Java并发之synchronized
Java多线程同步关键词是常用的多线程同步手段.它可以修饰静态类方法,实例方法,或代码块.修饰static静态方法时是对整个类加锁. 一.实现原理 在JVM中对象内存分三块区域,对象头.实例数据.对齐 ...
- visualstudio2017 +EF+Mysql生成实体数据模型闪退
VisualStudio2017+EF+MySql正常运转,费了不少劲,踏过不少坑 1.安装 Connector/NET 8.0.13 地址:https://dev.mysql.com/downloa ...
- 下载android sdk
- 利用python数据分析panda学习笔记之基本功能
1 重新生成索引 如果某个索引值不存在就引入缺失值 from pandas import Series,DataFrame import pandas as pd import numpy as np ...
- 4-1逻辑与运算符介绍 & 4-2逻辑或运算符介绍
后面括号内的(n++)不运算了. 4-2逻辑或运算符介绍
- Number()、parseInt()、parseFloat()的区别:
Number().parseInt().parseFloat()的区别: Number()的强制类型转换与parseInt()和parseFloat()方法的处理方式相似,只是它转换的是整个值,而不是 ...
- window.location js截取url地址
window.location方法的说明 原文链接: http://jiantian.org/index.php?page_id=2 window.location.href 整个URl字符串(在浏览 ...
- UVaLive 3902 Network (无根树转有根树,贪心)
题意:一个树形网络,叶子是客户端,其他的是服务器.现在只有一台服务器提供服务,使得不超k的客户端流畅,但是其他的就不行了, 现在要在其他结点上安装服务器,使得所有的客户端都能流畅,问最少要几台. 析: ...