Gridview中绑定DropDownList
1、页面代码
<asp:TemplateField HeaderText="等级">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# FormatUserlevel(Eval("User_UserLevel"))%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
//这个label的作用是为了在后台控制 当你点击编辑按钮的时 DropDownList 的选中值, <asp:Label ID="Label7" runat="server" Text='<%# Eval("User_UserLevel")%>' Visible="false"></asp:Label>
<asp:DropDownList ID="ddl_userLevel" runat="server" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
将此列设为模版,在现实数据的时候是以label形式,当点击控件自带的编辑按钮的时候就是以DropDownList形势显示
2、后台代码
1、页面代码 将此列设为模版,在现实数据的时候是以label形式,当点击控件自带的编辑按钮的时候就是以DropDownList形势显示
2、后台代码 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
SystemMemberLevel bll = new SystemMemberLevel();
IList<SystemMemberLevelModel> list = bll.GetAllList();
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = ((DropDownList)e.Row.FindControl("ddl_userLevel"));
Label lb = ((Label)e.Row.FindControl("Label7")); if (ddl != null)
{
ddl.DataSource = list;
ddl.DataTextField = "name";
ddl.DataValueField = "id";
ddl.SelectedValue = lb.Text;
ddl.DataBind();
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
SystemMemberLevel bll = new SystemMemberLevel();
IList<SystemMemberLevelModel> list = bll.GetAllList();
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = ((DropDownList)e.Row.FindControl("ddl_userLevel"));
Label lb = ((Label)e.Row.FindControl("Label7")); if (ddl != null)
{
ddl.DataSource = list;
ddl.DataTextField = "name";
ddl.DataValueField = "id";
ddl.SelectedValue = lb.Text;
ddl.DataBind();
}
}
}
Gridview中绑定DropDownList的更多相关文章
- GridView 中绑定DropDownList ,下拉框默认选中Label的值
在GridView中,我们 有时候要绑定值. 前台绑定的代码可以这样 <asp:TemplateField HeaderText="当前状态" ItemStyle-Horiz ...
- 为GridView中的DropDownList赋值
<Bda:GridView ID="gvMessage" runat="server" Height="70px" Width=&qu ...
- GridView中实现DropDownList联动
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- GridView中给DropDownList动态绑定数据,及选择列表值后自动更新数据库
protected void sgvFile1_RowDataBound(object sender, GridViewRowEventArgs e) { DropDownList ddlAM = ( ...
- Js获取Gridview中Dropdownlist选中状态
在Gridview中加入Dropdownlist模板列,加入DropDownlist 是一种常用的操作,其中涉及到如何获取选择项和Gridview重新绑定两个要点. 如图 前台代码如下 <%@ ...
- 获取GridView中RowCommand的当前索引行(转)
获取GridView中RowCommand的当前索引行 前台添加一模版列,里面添加一个LinkButton 前台 (如果在后台代码中用e.CommandArgument取值的话前台代码就必须在按钮中设 ...
- 转:获取GridView中RowCommand的当前索引行
获取GridView中RowCommand的当前索引行 前台添加一模版列,里面添加一个LinkButton 前台 (如果在后台代码中用e.CommandArgument取值的话前台代码就必须在按钮中设 ...
- GridView中两个DropDownList联动
GridView中两个DropDownList联动 http://www.cnblogs.com/qfb620/archive/2011/05/25/2057163.html Html: <as ...
- Gridview中Datakeys 通过主键取得各列的值。
首先在初始化Gridview时候定义主键的数组. GridViewTeacherStudent.DataKeyNames=new string[] {"courseId",&quo ...
随机推荐
- 数组名的含义.xml
pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...
- cdh5.4、cm5.4 安装详细步骤
安装准备: 1.centos6.5 64位 虚拟机,内存分配4G.硬盘位20G 2.cm5.4 cdh5.4 包 安装步骤 一.centos安装完后,进行系统配置 1.关闭防火墙 service ip ...
- python中的静态方法和类方法
在python中,各种方法的定义如下所示: class MyClass(object): #在类中定义普通方法,在定义普通方法的时候,必须添加self def foo(self,x): print & ...
- leetcode:Palindrome Number
Question: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Cou ...
- spring依赖注入原理剖析
PropertyDefinition.java package junit.test; public class PropertyDefinition { private String name; p ...
- PHP中mysql_affected_rows()和mysql_num_rows()区别
mysql_affected_rows -- 取得前一次 MySQL 操作所影响的记录行数mysql_num_rows -- 函数返回结果集中行的数目. config.php <?php hea ...
- 给一已经排序数组A和x,求A中是否包含两个元素之和为x
亲爱的大神老爷们,这是小渣第一次写blog,欢迎大家来喷(批评指正),算法渣因为面试中连这道题都不会写就自己琢磨了一下,也参考了网上大家的做法 解法一: 思路:从首尾向目的靠拢,因为已经排序,[假设存 ...
- redhat 挂载 iso文件 提示 mount :not a directory
- php--opp--2.什么是类,什么是对象,类和对象这间的关系
类的概念:类是具有相同属性和服务的一组对象的集合.它为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个主要部分.在面向对象的编程语言中,类是一个独立的程序单位,它应该有一个类名并包括属 ...
- Instagram的技术探索2(转)
原文:http://www.cnblogs.com/xiekeli/archive/2012/05/28/2520770.html 前一篇翻译了Instagram blog上的一篇文章<What ...