[英]How to make link button on grid view invisible when I click on it?
我有一個帶有鏈接按鈕的網格視圖。 單擊它時,我要執行一些操作,並且還需要使單擊的鏈接按鈕不可見。 如何使其不可見?
我的代碼:
<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();
}
}
我個人將使用Knockout JS或jQuery來管理所有客戶端功能,就像隱藏和處理html元素一樣。
將此添加到您的GridView1_RowCommand事件
LinkButton mybutton = (LinkButton)sender;
mybutton.Visible = false;
使用javascript隱藏它。 添加onclientclick事件並在javascript中編寫代碼將其隱藏。 首先運行客戶端代碼,然后運行服務器端。 因此,該按鈕將在那時隱藏。
試試這個
protected void gridview__RowCommand(object sender, GridViewRowEventArgs e)
{
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
LinkButton lnkbtn = (LinkButton)row.FindControl(”lnkbtnActionNames”);
lnkbtn .Visible = false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.