DropdownList 用法
1. 前端绑定drowdownlist
a) 模板列datasource直接绑定
前端
<asp:TemplateField HeaderText="Certificate Type" HeaderStyle-Width="10%"><ItemTemplate><asp:DropDownList ID="ddlCertificateType" runat="server" DataSource='<%# BindDdl()%>' DataValueField="iItemID" DataTextField="cField1"></asp:DropDownList></ItemTemplate><ItemStyle HorizontalAlign="Left" /></asp:TemplateField>
后台
Protected Function BindDdl() As DataTableReturn tools.GetLookupList("CERTIFICATETYPE", "maintsort")End Function
b) 数据源绑定
<asp:DropDownList ID="cboAccountType" Runat="server" AutoPostBack="True" Width="100%"DataSourceID="oDSAccountType" DataTextField="cField1" DataValueField="cField2" > </asp:DropDownList><asp:SqlDataSource ID="oDSAccountType" runat="server" ConnectionString="<%$ ConnectionStrings:VOSConnectionString %>" SelectCommand="VSP_Maintenance_GetItems" SelectCommandType="StoredProcedure"><SelectParameters><asp:Parameter DefaultValue="PAYSACCOUNT" Name="cCatCode" Type="String" /><asp:Parameter DefaultValue="SORTORDER" Name="cOrderBy" Type="String" /><asp:Parameter DefaultValue="0" Name="iNotForComboBoxes" Type="Int64" /><asp:Parameter DefaultValue="1" Name="RtnAllField" Type="Int64" /></SelectParameters></asp:SqlDataSource>
c) 绑定数据
Private Sub BindRcbStudioManager()Dim dtStudioManager As DataTable = (New StudioMgr).GetStudioManager(Session("iStudioID"))Me.rcbstudioManager.DataSource = dtStudioManagerMe.rcbstudioManager.DataTextField = "studioManager"Me.rcbstudioManager.DataValueField = "iStudioManagerID"Me.rcbstudioManager.DataBind()End Sub
2. Dropdownlist 特性
<asp:DropDownList ID="cboAccountType" Runat="server" AutoPostBack="True" Width="100%" > </asp:DropDownList>
如果AutoPostBack=True, 那么Postback时,添加的属性(Attributes)会丢失,因此添加属性的代码要写在IsPostback之外,
这时需要在Page_Load时判断当前dropdownlist的当前选择值,比如: ucPaysBank.ascx.vb
a) 循环添加数据及属性
Private Sub loadCboAccountType()Dim oTblAccountType As DataTable = tools.GetLookupListAll("PAYSACCOUNT", "SORTORDER", 1, 1, 1)cboAccountType.Items.Clear()For Each oRow As DataRow In oTblAccountType.RowsDim item As New ListItemitem.Text = oRow("cField1").ToStringitem.Value = oRow("iItemID").ToStringitem.Attributes.Add("cField2", oRow("cField2").ToString)cboAccountType.Items.Add(item)NextEnd Sub
b) 显示属性值
dim cField2 as string = cboAccountType.SelectedItem.Attributes.Item("cField2")
c) 添加值
cboPayment.Items.Clear()
cboPayment.Items.Add(New ListItem("", -1))
cboPayment.Items.Add(New ListItem("Final Payment", 1))
cboPayment.Items.Add(New ListItem("N/A", 2))
d) 取值
//获取value值$("#ddlSubmodel").val();//获取text值$("#ddlSubmodel").find("option:selected").text();
4. Dropdown List可以多选,且出现Checkbox 需引入
<link href="../App_Themes/bootstrap/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../Scripts/bootstrap/bootstrap-multiselect.js"></script>
DropdownList 用法相关推荐
- @HTML.RadioButtonFor和@Html.DropDownList用法
1.@Html.RadioButtonFor用法很简单 <label class="radio radio-inline">@Html.RadioButton(&quo ...
- asp:DropDownList用法
DropDownList前台: <asp:DropDownList runat="server" ID="drop" AutoPostBack=" ...
- 精简DropDownList用法
ViewBag.TypeID = new SelectList(db.TType, "ID", "Name", model.TypeID); @Html.Dro ...
- php dropdownlist,Yii2中DropDownList简单用法示例
本文实例讲述了Yii2中DropDownList简单用法.分享给大家供大家参考,具体如下: 这里以实际应用为例讲解Yii2 DropDownList用法. 有一张分类表,无限极分类那种,表结构如下,p ...
- .net MVC 下拉多级联动及MVC Html.DropDownList 和DropDownListFor
第一种方式 前台html <div style="margin:50px 0"><span>省份:</span><select id=&q ...
- php dropdownlist,Yii2框架dropDownList下拉菜单用法实例分析
本文实例讲述了Yii2框架dropDownList下拉菜单用法.分享给大家供大家参考,具体如下: dropDownList是yii框架中一个自带的下拉功能了解,我们可以直接使用dropDownList ...
- DropDownList的用法
DropDownList是一个下拉列表菜单,平时我们也会经常用到,下面就来看看如何绑定值 1> 静态添加,就是说在值都很明确的情况下 ListItem list1 = new ListI ...
- ListBox,CheckBoxList,DropDownList,RadioButtonList的常见用法
http://www.cnblogs.com/youchun/archive/2009/12/27/1633655.html 转载于:https://www.cnblogs.com/modernsky ...
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
在做 BS架构的项目时,经常遇到 需要用js 来调用 asp.net 服务器端控件的值. 大多数的 控件他的值都可以通过js调用它的 value属性来获得此控件的值,但是也有例外的情况. 经常用的 L ...
最新文章
- js表单提交,支持图片上传,包含后端php代码
- 虚拟化如何做实?详解戴尔2.0版解决方案
- 鸿蒙系统手机还会出吗,华为最强手机即将到来,可能还有华为鸿蒙系统加入!你期待吗?...
- xs_run加密还原
- Python入门100题 | 第011题
- 读jQuery之二十(Deferred对象)
- Linux内核深入理解中断和异常(7):中断下半部:Softirq, Tasklets and Workqueues
- 学生考勤系统设计mysql_学生考勤系统的设计与实现(Eclipse,MySQL)
- ubuntu19 磁盘分区管理及磁盘挂载
- 一周市场摘抄20210125
- 广发股票交易接口做什么的?
- Predicting drug–disease associations through layer attention graph convolutional network
- DDL、DML和DCL的理解(1、总述)
- 51nod2943 旅行者
- 英语听力采用计算机化考试,北京高考英语听力机考有什么特点?
- 软件质量保证与测试大作业,软件测试大作业.docx
- 离开手机的一天 天才小熊猫_文章《熊猫30天》
- SQL 2012 安装失败解决方案
- 【数据挖掘】聚类 Cluster 矩阵转换 数据矩阵 - 相似度矩阵 ( 二元变量简介 | 二元变量可能性表 | 对称二元变量 | 简单匹配系数 | 非对称二元变量 | Jaccard 系数 )
- Kotlin 学习笔记(十四)浅读协程