zoukankan      html  css  js  c++  java
  • DataGrid中DropDownList的动态绑定和触发DropDownList事件

    我在写DataGrid控件中子控件事件时候,DropDownList的事件相比而言麻烦一点,在此,我简单罗列如下(我在此处为了方便这里都用DataGrid中的隐藏列存储我所要的数据):

    一、DropDownList的动态绑定,只需在DataGrid1_ItemDataBound的事件中,取出数值进行匹配,便可以了,具体代码如下:
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
       if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem)) 
       {
        string StrPower = e.Item.Cells[3].Text; // 用隐藏列取出数据
        DropDownList DrpRole = (DropDownList)e.Item.Cells[4].FindControl("DrplRole");
        for(int i=0;i<DrpRole.Items.Count;i++)
        {
         if(StrPower.Equals(DrpRole.Items[i].Value))
         {
          DrpRole.Items[i].Selected = true;

         }
        }    
       }
      }

    二、触发DataGrid中DropDownList的事件

    前台:

    <asp:TemplateColumn HeaderText="分配角色">
            <ItemTemplate>
             <asp:DropDownList id="DrplRole" runat="server" Width="120px" OnSelectedIndexChanged="DrplRole_SelectedIndexChanged"
              AutoPostBack="True">
              <asp:ListItem Value="未分配权限">未分配权限</asp:ListItem>
              <asp:ListItem Value="开单员">开单员</asp:ListItem>
              <asp:ListItem Value="维护员">维护员</asp:ListItem>
             </asp:DropDownList>
            </ItemTemplate>
           </asp:TemplateColumn>

    注:  AutoPostBack="True" 千万不能落下


    后台:

    public void DrplRole_SelectedIndexChanged(object sender, System.EventArgs e)
      {
       // 选择用户类型   semir.customClass.database dbnew = new semir.customClass.database();
       DropDownList DrplRole = (DropDownList)sender;
       TableCell cell = (TableCell)DrplRole.Parent;
       DataGridItem item = (DataGridItem)cell.Parent;

       string StrPower = ((DropDownList)sender).SelectedItem.ToString(); // 取出DropDownList选中项文本
       int ITid = Convert.ToInt32(item.Cells[0].Text);    // 取出该行的第一格的数据(主键)
       string sqlUpPower = "update ITUsers set ITPower='"+StrPower+"' where ITID='"+ITid+"'";
       dbnew.DatabaseCommand(sqlUpPower); // 数据库操作

       BindDataUser(); // 绑定数据    
      }



  • 相关阅读:
    weblogic 未授权命令执行漏洞(CVE-2020-14882,CVE-2020-14883)复现
    sqlmap之--os-shell命令执行原理
    HTTP协议层面绕过WAF
    windows下过安全狗
    [SUCTF 2019]Pythonginx
    warmup(HCTF 2018)
    phpmyadmin 4.8.1 远程文件包含漏洞(CVE-2018-12613)
    phpMyAdmin写入WebShell(二)
    phpMyAdmin写入WebShell(一)
    [SUCTF 2019]EasySQL
  • 原文地址:https://www.cnblogs.com/skylaugh/p/352333.html
Copyright © 2011-2022 走看看