• 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);         
           
              //审核用户的申请
             //....(略)

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

          }
  • 相关阅读:
    Istio技术与实践02:源码解析之Istio on Kubernetes 统一服务发现
    Istio技术与实践01: 源码解析之Pilot多云平台服务发现机制
    深度剖析Kubernetes API Server三部曲
    深度剖析Kubernetes API Server三部曲
    深度剖析Kubernetes API Server三部曲
    深入了解Kubernetes REST API的工作方式
    Cassandra schema version 不一致
    ByteToMessageDecoder
    Byte Bit
    为什么要用Executors.defaultThreadFactory().newThread(run);创建线程?
  • 原文地址:https://www.cnblogs.com/sinkzephyr/p/862594.html
Copyright © 2020-2023  润新知