DropDownList
来源:互联网 发布:梦三版本优化在第几节 编辑:程序博客网 时间:2024/05/29 15:19
今天才真正理解DrowDownList中的属性是什么意思:
DataSource是所需要的所有数据集
DataTextField是下拉列表中显示给用户看的数据,是这一选项中的text值。
DataValueField是每一个选项的唯一Value值类似于JS选择的ID值,NAME值。因为dropdownlist是通过value属性进行选择的。
还有一个SelectValue,就是选中的那个value值,从而得到所对应的选项。
DataTextField用来作显示内容,一般给别人看,例如是一张表的某个字段的内容。
DataValueField用来放唯一性的字段值,一般是主键。
DataTextField是显示出来的内容,
DataValueField是controlid.selectedvalue的值。
百度的关于DropDownList和DropDownListFor的区别
一、非强类型:
Controller:
ViewData["AreId"] = from a in rp.GetArea()
select new SelectListItem {
Text=a.AreaName,
Value=a.AreaId.ToString()
};
View:
@Html.DropDownList("AreId")
还可以给其加上一个默认选项:@Html.DropDownList("AreId", "请选择");
二、强类型:
DropDownListFor常用的是两个参数的重载,第一参数是生成的select的名称,第二个参数是数据,用于将绑定数据源至DropDownListFor
Modle:
public class SettingsViewModel
{
Repository rp =new Repository();
public string ListName { get; set; }
public IEnumerable<SelectListItem> GetSelectList()
{
var selectList = rp.GetArea().Select(a => new SelectListItem {
Text=a.AreaName,
Value=a.AreaId.ToString()
});
return selectList;
}
}
Controller:
public ActionResult Index()
{
return View(new SettingsViewModel());
}
View:
@model Mvc3Applicationtest2.Models.SettingsViewModel
@Html.DropDownListFor(m=>m.ListName,Model.GetSelectList(),"请选择")
- dropdownlist
- DropDownList
- DropDownList
- DropDownList
- dropdownlist
- DropDownList
- dropdownlist
- dropdownlist
- DropDownList
- DropDownList
- DropDownList
- DropDownList
- dropdownlist
- dropdownlist绑定
- 绑定dropdownlist
- DropDownList专题
- DropDownList触发
- DropDownList用法
- 如何开发一个流畅的云计算架构?
- php中mysql操作的buffer知识
- maven管理SpringMVC+Mybatis无法加载resource资源文件解决办法
- getopt_long使用
- 90年代谁最强?乔丹不可撼动石佛上榜
- DropDownList
- EasyUI 中combotree 默认不能选择父节点
- androidのadb命令终端实时打印cpu资源
- eclipse屏蔽恶心的系统alt键
- 性能优化之PHP优化
- SAP实施方法论之探讨-现状调研与需求分析
- orocos Logger 类的设计
- Grunt的配置及使用(压缩合并js/css)
- hibernate 懒加载