创建一:
List<SelectListItem> items = new List<SelectListItem>()
{
new SelectListItem(){Text="Text1",Value="Value1",Selected=false},
new SelectListItem(){Text="Text2",Value="Value2",Selected=true},
new SelectListItem(){Text="Text3",Value="Value3",Selected=false},
new SelectListItem(){Text="Text4",Value="Value4",Selected=false}
};
ViewData["Categories"] = items;
前台:
@Html.DropDownListFor(model => model.ClassId, ViewData["Categories"] as List<SelectListItem>"请选择") 创建二:
List<Models.T_CMS_Class> list = db.T_CMS_Class.ToList();
SelectList items = new SelectList(list, "ClassId", "ClassName");
ViewBag.ClassId = items;
前台:
@Html.DropDownListFor(model => model.ClassId, ViewBag.ClassId as SelectList, "请选择")
@Html.ListBoxFor(model => model.ClassId, ViewBag.ClassId as List<SelectListItem>"请选择") 创建三:
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["Categories"] = items;
前台:
@Html.DropDownListFor(model => model.ClassId, ViewData["Categories"] as List<SelectListItem>"请选择") 创建四:
BLL.Sorts sortbll = new BLL.Sorts();
ViewBag.Select = sortbll.GetList().Select(d => new SelectListItem()
{
Text = d.Sname,
Value = d.Id.ToString(),
Selected = (model.Sid == d.Id) ? true : false
}); 前台:
@Html.DropDownListFor(model => model.Sid, ViewBag.Select as List<SelectListItem>, "请选择") 创建5
ViewBag.MusicType = new SelectList(typebll.GetList(), "TypeId", "TypeName");
ViewBag.MusicType = new SelectList(typebll.GetList(), "TypeId", "TypeName", MusicType);

  

DropdownList的处理总结的更多相关文章

  1. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  2. DropDownList 下拉框选择改变,促发事件和防全局刷新(记录)

    代码: <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:Script ...

  3. DropDownList实现可输入可选择

    1.js版本 <div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); positio ...

  4. js给DropdownList赋值

    ", "model": "APOLLO M/B1"}]; ; i < row.length; i++) { var addOption = do ...

  5. ASP.NET MVC 让@Html.DropDownList显示默认值

    在使用@Html.DropDownList的过程中,发现它的用法很局限,比如在加载的时候显示设定的默认项或者调整它的显示样式,在网上查了一些资料,终于把这个问题解决了. 一.View代码 @using ...

  6. GridView中实现DropDownList联动

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. "不能在 DropDownList 中选择多个项。"其解决办法及补充

    探讨C#.NET下DropDownList的一个有趣的bug及其解决办法 摘要: 本文就C#.Net 环境下Web开发中经常使用的DropDownList控件的SelectedIndex属性进行了详细 ...

  8. Asp.net mvc页面传值-- dropdownlist

    后台传值 List<ConfigParamInfo> paramList = configParamBLL.GetModelList(" and parentID=1" ...

  9. 怎么取得dropdownlist选中的ID值

    把数据库绑定在dropdownlist中,然后把选中的dropdownlist的项的ID值保存在另外的一个数据库中.怎么取得dropdownlist选中的ID值呢?? this.DropDownLis ...

  10. MVC5中后台提供Json,前台处理Json,绑定给Dropdownlist的例子

    MVC5中后台提供Json,前台处理Json,绑定给Dropdownlist的例子: 前端: 我们以前在前端定义了两个控件: <div class="row"> < ...

随机推荐

  1. background小结

    CSS背景属性Background详解 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. ...

  2. ScriptManager需要用到的JS

    <script type="text/javascript"> Sys.Application.add_load(function() { var form = Sys ...

  3. Email Cover Letter Format

    http://jobsearch.about.com/od/sampleletters/ig/Sample-Letter-Formats/Email-Message-Format.htm   Copy ...

  4. C#调用WebService实例和开发(转)

    1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...

  5. Struts2 实战经验 之 入门

    Struts2以WebWork为核心,采用拦截器机制处理用户请求,这样的设计使业务逻辑控制器能够与Servlet API完全脱离开,降低了藕联性. Part 1. 安装与配置 下载struts-2.3 ...

  6. C#生成缩略图的方法

    1.需要添加应用System.Drawing.dll 2.命名空间 using System.IO; using System.Drawing; using System.Drawing.Imagin ...

  7. Mysql查询高速缓存区

    为了提高查询速度,Mysql会维护一个内存区域(官方文档指出,大小至少41984B)对查询结果进行缓存,当查询时发现缓存区里有数据则直接返回结果而不用去执行sql语句. 查询命中的条件 每个缓存查询至 ...

  8. MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法

    MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法: 1.备份my.ini 2.在my.ini字段里 [mysqld] #socket=mysql skip-grant-tables ...

  9. HTML5 canvas 在线画笔绘图工具(三)

    组装画板(TDrawBuilder) 在这一小节中我们要把工具条和画板组装起来,让他们可以协同进行工作. 画板通过一个命名为TDrawBuilder来进行组装.在详细讲解TDrawBuilder对象之 ...

  10. java压缩/解压缩zip格式文件

    因为项目要用到压缩.解压缩zip格式压缩包,只好自己封装一个,对于网上流行的中文乱码的问题,本文的解决方法是用apache的包代替jdk里的.基本上还是比较好用的. 废话少说,直接上代码. }     ...