• GridView内嵌DropDownList操作


    效果:
     


    步骤:
    1.先把DropDownList所在的列转换成TemplateField(模板列)
    2.在GridView里添加三个事件OnRowEditing,OnRowCancelingEdit,OnRowUpdating
       再在事件上写上相应的代码

    代码片段:
    ASPX文件:
    <asp:GridView ID="gvRequestRoleList" runat="server" AutoGenerateColumns="False" CellPadding="4"
             ForeColor="#333333" GridLines="None" AllowPaging="True" OnPageIndexChanging="gvRequestRoleList_PageIndexChanging"
             OnRowEditing="gvRequestRoleList_RowEditing" OnRowCancelingEdit="gvRequestRoleList_RowCancelingEdit"
             OnRowUpdating="gvRequestRoleList_RowUpdating">
    .......
    <asp:TemplateField HeaderText="申请权限">
                   <EditItemTemplate>
                      <asp:DropDownList ID="ddlRequestRole" runat="server">
                         <asp:ListItem Value="Common">普通用户</asp:ListItem>
                         <asp:ListItem Value="Intermediate">中级用户</asp:ListItem>
                         <asp:ListItem Value="Senior">高级用户</asp:ListItem>
                         <asp:ListItem Value="Admin">超级用户</asp:ListItem>
                      </asp:DropDownList>
                   </EditItemTemplate>
                   <ItemTemplate>
                      <asp:Label ID="Label1" runat="server" Text='<%# Bind("RequestRoleCHName") %>'></asp:Label>
                   </ItemTemplate>
                </asp:TemplateField>
    .......
    </asp:GridView>

    CS文件:
    //用户按"修改权限"(更新)时
     protected void gvRequestRoleList_RowEditing(object sender, GridViewEditEventArgs e)
          {
             gvRequestRoleList.EditIndex = e.NewEditIndex;        
              //绑定数据
             RequestRoleListDataBind();
          }

    //用户取消操作时
          protected void gvRequestRoleList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
          {
             gvRequestRoleList.EditIndex = -1;
              //绑定数据
             RequestRoleListDataBind();
          }

    //更新操作
          protected void gvRequestRoleList_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
    //获得DropDownList 控件
             DropDownList ddlRequestRole = gvRequestRoleList.Rows[e.RowIndex].Cells[5].FindControl("ddlRequestRole") as DropDownList;
             string roleName = ddlRequestRole.SelectedItem.Value;
             Label lblUserName = gvRequestRoleList.Rows[e.RowIndex].Cells[2].FindControl("lblUserName") as Label;
             string userName = lblUserName.Text;

              //更新用户的角色
             ChangeRole(userName, roleName);         
           
              //审核用户的申请
             //....(略)

             //刷新页面
              //....(略)

          }
  • 相关阅读:
    co coa ch ina
    提高英语听力最好的学习方法
    http://www.funnygames.us/search/?s=balance
    flash
    https://github.com/search?l=ObjectiveC&p=2&q=cocos&ref=searchbar&type=Repositories
    game.m https://github.com/kayrules/Cocos2dEndlessPlatformerGame
    2013年下半年学习计划
    Javascript判断数据类型
    vue组件自定义属性命名
    BZOJ 1018 线段树维护连通性
  • 原文地址:https://www.cnblogs.com/sinkzephyr/p/862594.html
Copyright © 2020-2023  润新知