创建一:
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. [记录]关于vertical-align单/多选框与说明文字对齐效果

    效果图:    第一张使用label标签,第二张没有使用.. 使用label标签,middle对齐方式的单选框下降了1px 而没有使用label标签,sub对齐方式的 却 居 中 了 =_= 不太理解 ...

  2. c语言字符串比较函数strcmp

    strcmp(s1,s2) 说明: 当s1<s2时,返回值<0 当s1=s2时,返回值=0 当s1>s2时,返回值>0两个字符串自左向右逐个字符相比(按ASCII值大小相比较) ...

  3. 判断浏览器IE6

    <!--[if lte IE 6]><LINK rel="stylesheet" type="text/css" href="ima ...

  4. sqlserver2005仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'SendMealAddress'中为标识列指定显式值。

    ps = con.prepareStatement("insert into SendMealAddress values(null,?,?,?,?)"); 表有一列是自增长的标识 ...

  5. Android listview 的优化

    接[Android listview的应用][1] 在我们上一篇[Android listview的应用][1]中,我们的adapter中的getView()方法中每次都将布局重新加载一遍,这样就会导 ...

  6. php-fpm日志告警"seem busy"

    php-fpm日志中出现"WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.m ...

  7. 使用SelectClipRgn注意事项

    SelectClipRgn 函数功能:该函数选择一个区域作为指定设备环境的当前剪切区域. 函数原型:int SelectClipRgn(HDc hdc, HRGN hrgn): 参数: hdc:设备环 ...

  8. nginx模块开发获取post参数

    > 您好!>     我想请问下nginx模块里面怎么获取post参数,能有具体的代码更好!谢谢> 对于 "application/x-www-form-urlencode ...

  9. jQuery的touchstart,touchmove,touchend的获取位置

    $('#webchat_scroller').on('touchstart',function(e) { var touch = e.originalEvent.targetTouches[0]; v ...

  10. Qt5 基于TCP传输的发送/接收文件服务器(支持多客户端)

    一.实现功能 1.服务器端选择待发送的文件,可以是多个 2.开启服务器,支持多客户端接入,能够实时显示每个客户端接入状态 3.等待所有客户端都处于已连接状态时,依次发送文件集给每个客户端,显示每个客户 ...