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;
                    }
                }
            }
                               

        }

  • 相关阅读:
    [ACM_模拟] ZJUT 1155 爱乐大街的门牌号 (规律 长为n的含k个逆序数的最小字典序)
    [ACM_搜索] ZOJ 1103 || POJ 2415 Hike on a Graph (带条件移动3盘子到同一位置的最少步数 广搜)
    [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
    [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)
    [JAVA] java_实例 获得系统字体
    [JAVA] java仿windows 字体设置选项卡
    [JAVA] 一个可以编辑、编译、运行Java简单文件的记事本java实现
    [ACM_模拟] POJ 1094 Sorting It All Out (拓扑排序+Floyd算法 判断关系是否矛盾或统一)
    JS的数组相关知识
    JS的join方法
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1642806.html
Copyright © 2011-2022 走看看