我有一个带链接按钮的网格视图。点击它时,我想执行一些操作,还需要使点击的链接按钮不可见。如何让它隐形?
我的代码:
<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();
}
}
答案 0 :(得分:0)
我个人会使用Knockout JS或jQuery来管理我的所有客户端功能,就像隐藏和操作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;
}