ASP.NET 数据绑定到列表控件
<div>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
</div>
protected void Page_Load(object sender, EventArgs e)
{
List<string> fruit = new List<string>();
fruit.Add("Kiwi");
fruit.Add("Pear");
fruit.Add("Mango");
fruit.Add("Blueberry");
fruit.Add("Apricot");
fruit.Add("Banana");
fruit.Add("Peach");
fruit.Add("Plum"); ListBox1.DataSource = fruit;
DropDownList1.DataSource = fruit;
CheckBoxList1.DataSource = fruit;
RadioButtonList1.DataSource = fruit; this.DataBind();
}
进阶:数据绑定到字典集合
protected void Page_Load(Object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// Use integers to index each item. Each item is a string.
Dictionary<int, string> fruit = new Dictionary<int, string>(); fruit.Add(, "Kiwi");
fruit.Add(, "Pear");
fruit.Add(, "Mango");
fruit.Add(, "Blueberry");
fruit.Add(, "Apricot");
fruit.Add(, "Banana");
fruit.Add(, "Peach");
fruit.Add(, "Plum"); // Define the binding for the list controls.
MyListBox.DataSource = fruit;
/*
MyListBox.DataTextField = "Value";
MyListBox.DataValueField = "Key";
*/
// Choose what you want to display in the list.
MyListBox.DataTextField = "Value"; // Activate the binding.
this.DataBind();
}
}
html code:
<select name="MyListBox" id="MyListBox" >
<option value="1">Kiwi</option>
<option value="2">Pear</option>
<option value="3">Mango</option>
<option value="4">Blueberry</option>
<option value="5">Apricot</option>
<option value="6">Banana</option>
<option value="7">Peach</option>
<option value="8">Plum</option>
</select>
ASP.NET 数据绑定到列表控件的更多相关文章
- ASP .NET MVC HtmlHelper扩展——简化“列表控件”的绑定
在众多表单元素中,有一类<select>元素用于绑定一组预定义列表.传统的ASP.NET Web Form中,它对应着一组重要的控件类型,即ListControl,我们经常用到DropDo ...
- 数据绑定(五)使用集合对象作为列表控件的ItemsSource
原文:数据绑定(五)使用集合对象作为列表控件的ItemsSource ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值,ItemsSource里存放的是一条一条 ...
- asp.net学习之Repeater控件
asp.net学习之Repeater控件 文章摘自:http://www.cnblogs.com/shipfi/archive/2009/10/19/1585703.html Repeater控件和D ...
- asp.net动态网站repeater控件使用及分页操作介绍
asp.net动态网站repeater控件使用及分页操作介绍 1.简单介绍 Repeater 控件是一个容器控件,可用于从网页的任何可用数据中创建自定义列表.Repeater 控件没有自己内置的呈现功 ...
- ASP.NET中 WebForm 窗体控件使用及总结【转】
原文链接:http://www.cnblogs.com/ylbtech/archive/2013/03/06/2944675.html ASP.NET中 WebForm 窗体控件使用及总结. 1.A, ...
- asp.net学习之DataList控件
asp.net学习之DataList控件 DataList控件与Repeater控件一样由模板驱动,与Repeater控件不同的是: DataList控件默认输出是一个HTML表格.DataLis ...
- WPF进阶技巧和实战03-控件(3-文本控件及列表控件)
系列文章链接 WPF进阶技巧和实战01-小技巧 WPF进阶技巧和实战02-布局 WPF进阶技巧和实战03-控件(1-控件及内容控件) WPF进阶技巧和实战03-控件(2-特殊容器) WPF进阶技巧和实 ...
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
说说WebForm: 数据列表控件: WebForm 下的列表绑定控件基本就是GridView.DataList.Repeater:当然还有其它DropDownList.ListBox等. 它们的共同 ...
随机推荐
- springMvc里的mvc:resources与静态资源的访问
在进行Spring MVC的配置时,通常我们会配置一个dispatcher servlet用于处理对应的URL.配置如下: <servlet> <servlet-name&g ...
- 【MySQL】死锁问题分析
1.MySQL常用存储引擎的锁机制: MyISAM和MEMORY采用表级锁(table-level locking) BDB采用页面锁(page-level locking)或表级锁,默认为页面锁 ...
- spring-aop代理的生效原理
主要说下spring里aop的生效的原理吧,并不是讲底层的cglib和gdk动态代理. 还是老一套的分析流程,先找到了aop的标签的handler,然后看下在解析这个标签的时候,都干了些什么,其实主要 ...
- Windows 8.1 Update中的小改变
在Build 2014大会中,发布了Windows 8.1 Update的更新,并将于4月8日通过Windows Update进行推送.但是,在MSDN订阅下载中,带有该更新的镜像已经可以在4月3号放 ...
- hdu2504
代码一: //这个没有过 #include<stdio.h> //typedef long long ll; int main() { int T; scanf("%d" ...
- 区间DP石子合并问题 & 四边形不等式优化
入门区间DP,第一个问题就是线性的规模小的石子合并问题 dp数组的含义是第i堆到第j堆进行合并的最优值 就是说dp[i][j]可以由dp[i][k]和dp[k+1][j]转移过来 状态转移方程 dp[ ...
- Android-Java构造代码块&构造方法隐式三行
构造代码块: 描述Teacher对象/实体: package android.java.oop06; public class Teacher { private int id = 007; priv ...
- Android GridView 滑动条设置一直显示状态
模拟GridView控件: <GridView android:id="@+id/picture_grid" android:layout_width="match ...
- [翻译] ASP.NET WebAPI 中的异常处理
原文链接:https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling 本文介绍 ...
- [实战演练]蜻蜓FM2014年校招笔试题目 - 规则二叉树
题目:某规则二叉树的定义是:对于树中任意两个叶结点A.B,他们与根结点的距离分别是d1和d2,|d1-d2|<=1.请写出函数 bool isRuledTree(Node *root)的代码实现 ...