创建一:
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. Web App 聊天样式

    意见反馈: @using CommonDB.EF @model IEnumerable<Pub_ChatLog> @{ ViewBag.Title = "意见反馈"; ...

  2. U - stl 的 优先队列 Ⅰ

    Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...

  3. seajs路径问题及源码分析

    seajs如此神奇,究竟是如何做到的呢,想知基原理,方可看其源码~~之前冲忙写下的,可能有点乱哦~~有什么不对的,欢迎拍砖!   如果进入seajs了管理范围,那么路径分为:   1.    /  或 ...

  4. Linux回归篇-基础恶补

    前言:  LINUX在之前仅仅了解一些皮毛知识,最近计划深入研究大数据,LINUX当然少不了,所以借此良机将LINUX也顺带添加进入学习的目录之中.为了知识的全面性,本文先恶补一下LINUX的基础,作 ...

  5. Oracle 修改密码 解锁

    1.怎么修改oracle用户密码 在以SYSDBA身份登陆时可以修改其他用户的密码,比如: SQL> alter user 用户名 identified by 新密码; 用户已更改. 这个是把U ...

  6. 【Xamarin 挖墙脚系列:Windows 10 一个包罗万象的系统平台】

    build2016 结束后,证实了微软之前的各种传言.当然,都是好消息. Windows10 上基本可以运行主流的任意的操作系统. Windows Linux(在内部版本143216中,支持了bash ...

  7. C#调用API函数EnumWindows枚举窗口的方法

    原文 http://blog.csdn.net/dengta_snowwhite/article/details/6067928 与C++不同,C#调用API函数需要引入.dll文件,步骤如下: 1. ...

  8. MFC可执行文件问题

    MFC生成的.exe可执行文件,在其它机子上无法正常执行.主要是MFC库链接方式的问题,使用MFC分动态连接和静态连接两种:   静态连接就是把需要的MFC库函数放进你的exe之中,这样,在MFC库函 ...

  9. javac: cannot execute binary file

    # java/jdk1.6.0_12/bin/javac-bash: java/jdk1.6.0_12/bin/javac: cannot execute binary file   后来检验,检查了 ...

  10. 读<<代码整洁之道>>的感想

    花去了近一周的时间浏览一下这本书.总体感觉这本书写得不错. 我发现自己以前写的代码时多么的糟糕.有很多改进之处... 同时我也发现写出优秀的代码不易.优秀的代码不仅仅易读,并且易修改,易维护,程序易维 ...