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的更多相关文章

  1. GridView 中绑定DropDownList ,下拉框默认选中Label的值

    在GridView中,我们 有时候要绑定值. 前台绑定的代码可以这样 <asp:TemplateField HeaderText="当前状态" ItemStyle-Horiz ...

  2. 为GridView中的DropDownList赋值

    <Bda:GridView ID="gvMessage" runat="server" Height="70px" Width=&qu ...

  3. GridView中实现DropDownList联动

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

  4. GridView中给DropDownList动态绑定数据,及选择列表值后自动更新数据库

    protected void sgvFile1_RowDataBound(object sender, GridViewRowEventArgs e) { DropDownList ddlAM = ( ...

  5. Js获取Gridview中Dropdownlist选中状态

    在Gridview中加入Dropdownlist模板列,加入DropDownlist 是一种常用的操作,其中涉及到如何获取选择项和Gridview重新绑定两个要点. 如图 前台代码如下 <%@ ...

  6. 获取GridView中RowCommand的当前索引行(转)

    获取GridView中RowCommand的当前索引行 前台添加一模版列,里面添加一个LinkButton 前台 (如果在后台代码中用e.CommandArgument取值的话前台代码就必须在按钮中设 ...

  7. 转:获取GridView中RowCommand的当前索引行

    获取GridView中RowCommand的当前索引行 前台添加一模版列,里面添加一个LinkButton 前台 (如果在后台代码中用e.CommandArgument取值的话前台代码就必须在按钮中设 ...

  8. GridView中两个DropDownList联动

    GridView中两个DropDownList联动 http://www.cnblogs.com/qfb620/archive/2011/05/25/2057163.html Html: <as ...

  9. Gridview中Datakeys 通过主键取得各列的值。

    首先在初始化Gridview时候定义主键的数组. GridViewTeacherStudent.DataKeyNames=new string[] {"courseId",&quo ...

随机推荐

  1. JS代码的简单重构与优化

    JS代码的简单重构与优化(适合新手) 原文  http://www.cnblogs.com/similar/p/5016424.html Demo . 1 //bad if (age > 20) ...

  2. 【LeetCode】101 - Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  3. SAS、R以及SPSS的比较__统计语言大战

  4. Python【基础第二篇】

    元组 元组的元素不可修改 元组的元素的元素可修改 字典 Python主文件判断 name == main python中一切事物都是对象 对象是基于类创建的 对象具有的所有功能都是从类里找的 int内 ...

  5. RFID之UID

    1 Unique identifier (UID) The VICCs are uniquely identified by a 64 bits unique identifier (UID). Th ...

  6. c++中获取字符cin,getchar,get,getline的区别

    http://www.imeee.cn/News/GouWu/20090801/221298.html cin.get()与getchar()函数有什么区别? 详细点..C++中几个输入函数的用法和区 ...

  7. 非官方的iOS设计指南

    非官方的iOS设计指南 有时候为iOS设计app并不是一件简单的事,但是如果你能找到正确的最新的苹果设备信息,并按照正确的方向,那么为iOS设计app或许会变得简单容易些. 关于这些指南 这些指南描述 ...

  8. IIS7 503错误 Service Unavailable

    把相应的Application Pools的process model的Identity属性设置成“LocalSystem”就OK了

  9. 理解C#值类型和引用类型

    网上偶尔浏览到这一篇文章,还不错就修改了下分享给大家. 工作许久了,可是对C#值类型和C#引用类型却一直无法很好的理解.这两天花了不少时间查找资料,看文章,终于有所收获,在此将自己理解整理出来,方便日 ...

  10. const型类成员

    一.关于const类成员函数有以下几个需要注意的地方: 1. 在普通的非const成员函数中,this的类型是一个指向类类型的const指针,而const成员函数中,this的类型是一个指向const ...