• GridView 中的button LinkButton 事件 CommandName


       一:          <asp:LinkButton ID="LinkButton1" runat="server" CommandName ="updateState"   Text="可用"
                     CommandArgument='<%#Eval("Roleid") %>'/> 

     protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           if (e.CommandName == "updateState")
           {

               LinkButton Lb = (LinkButton)sender;
               Lb.Text = "禁用"; 
             }     }

    LinkButton 可以触发CommandName ,Button ,imgeButon 不能触发

    二: <asp:ButtonField CommandName="ShowTeam"  HeaderText="团队信息"
                                    Text="团队信息" />
     protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           if (e.CommandName == "updateState")
           {
               Page.Alert("updateState");
               
            }
           if (e.CommandName == "ShowTeam")
           {
               Page.Alert(e.CommandArgument.ToString());  // e.CommandArgument得到当前行 的索引,可
            int ClientID = Convert.ToInt32(ClientGridview.DataKeys[index].Value.ToString());
    得到相应的 数据

     

     ((LinkButton)e.CommandSource).Text = "禁用";     由e.CommandSource得到事件源,也就是LinkButton, 就可以操作这个 linkButton 的属性了    }
           
        }

     

     protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           if (e.CommandName == "updateState")
           

               if (((LinkButton)e.CommandSource).Text.ToString() == "禁用")
               {
              
               ((LinkButton)e.CommandSource).Text="可用";
               }
               else

     

     三:通过onCommand 命令配置事件

    <asp:Button ID="garbage" OnCommand="garbage" OnClientClick="return confirm('确定设为垃圾问题吗?');"  runat="server" Text="垃圾处理"  visible="false " CommandName="garbage"  CommandArgument='<%#Eval("ID") %>'/>

        protected void Refer(object sender, CommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
           
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                var QuSupport = db.QuestionSupport.FirstOrDefault(q => q.ID == id);

                if (QuSupport != null)
                {
                    content.Text = QuSupport.SupportContent;  //得到Content的内容
                    QuSupport.IsRefereed = true; //设置引用为真
                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception)
                    {

                        throw;
                    }
                }
            }
                               

        }

  • 相关阅读:
    Balanced Binary Tree
    Minimum Depth of Binary Tree
    Path Sum
    Flatten Binary Tree to Linked List
    Distinct Subsequences
    Chp3: Stacks and Queue
    Chp2: Linked List
    Populating Next Right Pointers in Each Node
    Valid Palindrome
    Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1642806.html
Copyright © 2020-2023  润新知