点击它时如何使网格视图上的链接按钮不可见?

时间:2013-07-31 03:51:50

标签: c# asp.net gridview

我有一个带链接按钮的网格视图。点击它时,我想执行一些操作,还需要使点击的链接按钮不可见。如何让它隐形?

我的代码:

 <asp:TemplateField ShowHeader="true" HeaderText="Theory">
      <ItemTemplate>
           <asp:LinkButton ID="lb_theory" runat="server" CausesValidation="false" CommandArgument='<%#Eval("student_id")%>' OnClientClick="this.disabled = true; "   CommandName="theory_remove" Text="Remove"  
command = "lnk_Click" ></asp:LinkButton>
      </ItemTemplate>
      </asp:TemplateField>
            <asp:TemplateField ShowHeader="true" HeaderText="Practical">
                 <ItemTemplate>
                      <asp:LinkButton ID="lb_practical" runat="server" CausesValidation="false" 
                                CommandArgument='<%#Eval("student_id")%>'   CommandName="practical_remove" Text="Remove"></asp:LinkButton>
                 </ItemTemplate>
      </asp:TemplateField>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
     if (e.CommandName == "theory_remove")
     {
         string st_id = Convert.ToString(e.CommandArgument.ToString());
         string t_id = (string)Session["test"];
         SqlConnection con = obj.getcon();
         con.Open();
         string theory_state = "0";
         SqlCommand cmd = new SqlCommand("update student_vs_testsession_details set theory='" + theory_state+ "' WHERE student_id='" + st_id + "' and testsession_id='" + t_id + "'", con);
         int temp = cmd.ExecuteNonQuery();
     }
}

4 个答案:

答案 0 :(得分:0)

我个人会使用Knockout JSjQuery来管理我的所有客户端功能,就像隐藏和操作html元素一样。

答案 1 :(得分:0)

将此添加到GridView1_RowCommand事件

    LinkButton mybutton = (LinkButton)sender;
    mybutton.Visible = false;

答案 2 :(得分:0)

使用javascript来隐藏它。添加onclientclick事件并在javascript中编写代码以隐藏它。首先运行客户端代码然后运行服务器端。所以按钮将在那时隐藏。

答案 3 :(得分:0)

试试这种方式

protected void gridview__RowCommand(object sender, GridViewRowEventArgs e)
{


        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        LinkButton lnkbtn = (LinkButton)row.FindControl(”lnkbtnActionNames”);
        lnkbtn .Visible = false;


}