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. mybatis系列-16-spring和mybatis整合

    16.1     整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSess ...

  2. WCF基礎

    參考:http://www.cnblogs.com/MeteorSeed/archive/2012/04/24/2399455.html http://www.cnblogs.com/scy25114 ...

  3. 封装cookie.js、EventUtil.js、

    最近学习了javascript,封装好的东西看起来舒服,以备需要的时候拉出来,jquery对javascript做了很好的封装!以后会多用jquery多些 var CookieUtil = { get ...

  4. Eclipse中Maven工程缺少Maven Dependencies

    Eclipse在引入Maven工程后,找不到Maven Dependencies.使得代码报错,具体如下图所示: 而正常Maven的工程如下所示: 产生这种现象的原因可能是工程对应的开发环境改变,本地 ...

  5. 创建被访问的swf文件

    首先创建一个fla文件,名字叫movie.fla,在该文件库中放一个mc, 并将其拖放到舞台上,然后 命名为test_mc, 然后在库中给该mc绑定一个类,类名随意. 创建访问swf文件的swf文件 ...

  6. ssh-keygen -t rsa -f cloud.key ssh -i cloud.key <username>@<instance_ip>

  7. ApplicationIdle

    ApplicationIdle 不忙的时候调用此事件 ::Fmx::Forms::Application->OnIdle = ApplicationIdle; void __fastcall T ...

  8. Mongo技巧-连接数据库与修改表结构

    1. 连接非本机数据库 mongo.exe之后直接输入ip地址即可 mongo.exe 192.168.163.203 2. 修改表结构 mongo里面没有表结构这个概念,现在采用类似关系型数据库的形 ...

  9. Java断言assert

    public class Welcome{ public static void main(String[] args){ assert false; System.out.println(" ...

  10. DMOZ介绍以及如何提交

    转载自 http://www.cnblogs.com/freespider/archive/2009/12/28/1633818.html Dmoz介绍及怎么提交? 1.Dmoz目录简介: Dmoz是 ...