zoukankan      html  css  js  c++  java
  • 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;
                    }
                }
            }
                               

        }

  • 相关阅读:
    ES6:Iterator遍历器
    前端:对BFC的理解
    前端:性能优化之防抖与节流
    ES6新增数据类型Symbol
    ajax和fetch、aixos的区别
    我对js数据类型的理解和深浅(copy)的应用场景
    egg的基本使用
    前端:css3的过渡与动画的基础知识
    Java基础篇之类
    JAVA基础篇之Scanner
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1642806.html
Copyright © 2011-2022 走看看