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> ...
随机推荐
- python 二分法例子及冒泡排序
#!/usr/bin/env python #-*- coding:utf-8 -*- def binary_search(source_data,find_nu): mid = len(source ...
- Mysql数据库的打开和关闭
Mysql数据库的打开和关闭: 选择计算机(win7)-右键管理 在新窗口选择--服务 5 找到mysql,然后右键-启动(停止)
- opencv3.4.0 安装过程中出现的问题
重新安装opencv3.4.0 参考安装博客: opencv 安装版本测试:pkg-config --modversion opencv https://blog.csdn.net/cocoaqin/ ...
- windows下的套接字IO模型
一般情况下,IO操作的行为受两种因素的影响: IO操作对象的类型(阻塞还是非阻塞) 获取IO操作结果的方式(同步还是异步). 同步就是指操作的发起和操作结果的获取由调用者完成. 异步指操作发起由调用方 ...
- CCF 201512-4 送货 (并查集+DFS,欧拉路)
问题描述 为了增加公司收入,F公司新开设了物流业务.由于F公司在业界的良好口碑,物流业务一开通即受到了消费者的欢迎,物流业务马上遍及了城市的每条街道.然而,F公司现在只安排了小明一个人负责所有街道的服 ...
- C和FORTRAN的快速傅里叶/余弦/正弦变换(Fast Fourier/Cosine/Sine Transform)开源库分享
Takuya Ooura: General Purpose FFT Package, http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html. Free C & ...
- Java的多线程创建方法
1. 直接使用Thread来创建 package com.test.tt; public class ThreadEx extends Thread{ private int j; public vo ...
- C# sbyte[]转byte[]
http://stackoverflow.com/questions/2995639/sbyte-vs-byte-using-methodssbyte[] orig = ... byte[] arr ...
- 436. Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...
- 5-5 城市间紧急救援 (25分)【最短路spfa】
5-5 城市间紧急救援 (25分) 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速 ...