mvc 使用DropDownList
来源:互联网 发布:淘宝助理5.0官方 编辑:程序博客网 时间:2024/06/03 22:14
引用:http://www.cnblogs.com/jiangchao/archive/2009/07/21/1527920.html
- 原型一:
public static string DropDownList(this HtmlHelper htmlHelper, string name)
{
IEnumerable<SelectListItem> selectData = htmlHelper.GetSelectData(name);
return htmlHelper.SelectInternal(null, name, selectData, true, false, null);
}
第一种方式:
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem() { Text = "001", Value = "1", Selected = false });
items.Add(new SelectListItem() {Text = "002", Value = "2", Selected = false });
ViewData["items"] = items;
简化后:
var items = new List<SelectListItem>()
{
(new SelectListItem() {Text = "001", Value = "1", Selected = false}),
(new SelectListItem() {Text = "002", Value = "2", Selected = false})
};
将items值给ViewData:
ViewData["items"] = items;
在aspx中这样使用:
<%= Html.DropDownList("items") %>
生成的代码中,items将作为<select>标签的name和id值。
- 原型二:
public static string DropDownList(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList){ return htmlHelper.DropDownList(name, selectList, null);}
使用方法:
<%= Html.DropDownList("items", new List<SelectListItem>
{
(new SelectListItem() {Text = "001", Value = "1",}),
(new SelectListItem() {Text = "002", Value = "2",})
})%>
在这里,不需要ViewData传入值,第一个参数items作为标签的name和id的值。items也可以是任意的字符串。
- 原型三
- public static string DropDownList(this HtmlHelper htmlHelper, string name, string optionLabel)
{
IEnumerable<SelectListItem> selectData = htmlHelper.GetSelectData(name);
return htmlHelper.SelectInternal(optionLabel, name, selectData, true, false, null);
}
使用方法和第一种原型相同,string optionLabel作为一个缺省的空的选项。这样可以完成加入不需要选取任何选项的场景。
- mvc 使用DropDownList
- NET MVC DropDownList使用
- mvc中dropdownlist的使用
- ASP.NET MVC DropdownList 使用
- MVC中如何使用DropDownList
- 在ASP.NET MVC中使用DropDownList
- 在ASP.NET MVC中使用DropDownList
- 在ASP.NET MVC中使用DropDownList
- 在ASP.NET MVC中使用DropDownList
- ASP.NET MVC中DROPDOWNLIST的使用
- ASP.NET MVC中DropDownList的使用
- asp.net mvc Dropdownlist的使用绑定
- ASP.NET MVC DropDownList的使用
- mvc dropdownlist
- MVC DropDownList
- 详解ASP.NET MVC中DropDownList的使用
- 详解ASP.NET MVC中DropDownList的使用
- mvc dropdownlist 动态绑定
- 滑动窗口协议
- RFC文档目录
- c++_1
- gridfitdir法拟合曲面
- Java Applet实现声音和图像的协调
- mvc 使用DropDownList
- Android SDK 中提供的面向硬件的特性
- 深入了解字符集和编码
- 使用rsync从linux到linux或到windows对网站进行镜像备份
- c#连接数据库总结
- jsf真正所要的全部包
- 什么是32位和64位操作系统
- [SGU 104]Little Shop of Flowers(DP)
- 动态iptables防火墙:dynfw