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的常见数据绑定的更多相关文章

  1. js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)

    js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等) 欢迎访问原稿:http://hi.baidu.com/2wixia ...

  2. 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定

    aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...

  3. c#listbox使用详解和常见问题解决

    关于ListBox ListBox是WinForm中的 列表 控件,它提供了一个项目列表(一组数据项),用户可以选择一个或者多个条目,当列表项目过多时,ListBox会自动添加滚动条,使用户可以滚动查 ...

  4. Web控件文本框Reset的功能

    在前一篇中<怎样实现Web控件文本框Reset的功能>http://www.cnblogs.com/insus/p/4120889.html Insus.NET只实现了文本框的功能.单个或 ...

  5. Farseer.net轻量级开源框架 中级篇:数据绑定

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: DbFactory数据工厂 下一篇:Farseer.net轻量级开源框架 中级篇: ...

  6. ASP.NET数据绑定

    数据绑定是ASP.NET提供的另一种访问数据库的方法.与ADO.NET数据库访问技术不同的是:数据绑定技术可以让程序员不关注数据库连接.数据库命令以及如何格式化这些数据以显示在页面上等环节,而是直接把 ...

  7. ASP.NET数据绑定控件

    数据绑定控件简介 数据绑定分为:数据源 和 数据绑定控件 两部分,数据绑定控件通过数据源来获得数据,通过数据源来隔离数据提供者和数据使用者,数据源有:SqlDataSource,AccessDataS ...

  8. ASP.NET数据绑定控件简介

    •数据绑定分为数据源和数据绑定控件两部分(①数据绑定控件通过数据源获取和修改数据②数据绑定控件通过数据源隔离数据提供者和数据使用者)数据绑定控件→数据源→数据库•数据源:SqlDataSource(连 ...

  9. ASP.NET 数据绑定到列表控件

    <div> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> ...

随机推荐

  1. CentOS6.5 yum源设置

    在安装完CentOS后一般需要修改yum源,才能够在安装更新rpm包时获得比较理想的速度. 国内比较快的有163源.sohu源.这里以163源为例子. 1. cd /etc/yum.repos.d 2 ...

  2. RQNOJ魔法石之恋

    魔法石之恋 (stone.pas/c/cpp) [问题描述] 在<Harry Potter and the Sorcerer's Stone>中,想得到魔法石,必须要通过许许多多的测试和游 ...

  3. C++学习笔记1-使用数组进行vector初始化

    另外,如果是定义的时候,可以直接指定复制.比如:int s[5]={1,2,3,4,5};vector<int> v(s,s+5);就可以啦.

  4. 【转】Maven 入门

    [转]http://www.blogjava.net/jiangshachina/archive/2006/09/01/67080.html   Maven入门--概念与实例  最近由于工作原因在研究 ...

  5. 如何在html中引入jsx文件

    不使用webpack工具做react项目 1.引入react相关js文件 <script src="https://cdn.staticfile.org/react/16.4.0/um ...

  6. 525. Contiguous Array

    Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. ...

  7. Codeforces Round #374 (Div. 2)【A,B,C】

    = =C题这种DP打的少吧,记得以前最短路分层图打过这样子的,然后比赛前半个小时才恍然大雾...然后瞎几把还打错了,还好A,B手速快..上分了: A题: 计算B的连续个数的组数,每组的连续个数: 水题 ...

  8. 学习RESTFul架构

    一.RESTFul介绍 1.一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机 ...

  9. laravel V层

    V层 即视图层  也就是常用的html页面  但在laravel里后缀为php 视图层路径resources/views/视图名称.php

  10. javaScript中for-in语句

    for-in语句是一种精准的迭代语句,用来枚举对象的属性 实例: <!DOCTYPE html><html><head> <title>For-In S ...