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等. 它们的共同 ...
随机推荐
- 移动端 - APP测试要点
功能测试 1.运行 1)App安装完成后的试运行,可正常打开软件. 2)App打开测试,是否有加载状态进度提示. 3)App页面间的切换是否流畅,逻辑是否正确. 2.注册 1)同表单编辑页面 2)用户 ...
- 阿里云服务器 OSS的使用限制
使用限制 更新时间:2019-02-12 16:50:27 编辑 · OSS的使用限制及性能指标如下: 限制项 说明 归档存储 已经存储的数据从冷冻状态恢复到可读取状态需要 1 分钟的等待时间. ...
- MCU_头文件编写
头文件中一般放一些重复使用的代码,如:常量.变量.宏等的定义,函数的声明.当使用#include语句引用头头文件时,相当于将头文件中的内容复制到#include处. 头文件一般形式: #ifndef ...
- [javascript] javascript 实现数据滚动加载
// tpl generate var tmpl = (function (cache, $) { return function (str, data) { var fn = !/\s/.test( ...
- poj 2046&&poj1961KMP 前缀数组
Power Strings Time Limit: 3000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Jav ...
- Excel中单元格、超级链接形成超级链接单元格
使用函数 HYPERLINK(超链接,显示文字) =HYPERLINK("http://www.cnblogs.com/Vpygamalion/","李汉超") ...
- C#读取excel文件提示未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序
错误描述: 在VS2010执行读取excel文件时,报错"未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序" 业务代码: //下 ...
- nodejs学习(imooc课程笔记, 主讲人Scott)
课程地址: 进击Node.js基础(一) 进击Node.js基础(二) 1. nodejs创建服务器 var http = require('http'); //加载http模块 //请求进来时, 告 ...
- Linux系统软件包的管理(4)
虽然使用源码编译安装可以具有提高速度个性化的定制等优点,但对于 Linux发行商来说,则不容易管理软件包,毕竟不是每个人都会进行源码编译的,如果能够将软件预先在相同的硬体与系统上面编译好在发布的话,不 ...
- 大众点评Cat--架构分析
转自:http://blog.csdn.net/szwandcj/article/details/51025669 Cat功能强大且多,光日志的报表和图表分析就有十几种,但文档却很少,寥寥无几找到一些 ...