• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
无忧岛主
实践是检验真理的唯一标准
博客园    首页    新随笔       管理    订阅  订阅
Gridview中的linkbutton

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

    }

 

如果本文引用了你的文章而未注明,请及时联系我。
posted on 2012-07-01 09:13  无忧岛主  阅读(409)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3