Or Handle that in UI. If you have one more value for visibility(VisibilityFlag from backend), that's enough. It'll automatically show/hide button depends on value.
<asp:LinkButton ID="lnbResend" runat="server" Visible='<%Eval("VisibilityFlag")%>'></asp:LinkButton>
show and hide link button in grid view | The ASP.NET Forums[
^]
Or Handle that in event bubbling. Check for not null in code-behind.
protected void LinkButton_Click(Object sender, CommandEventArgs e)
{
if (e.CommandArgument != null)
{
Response.Redirect("YourPage.aspx?IdPassed=" + e.CommandArgument.ToString());
}
}
https://www.hightechnology.in/how-to-redirect-to-another-page-by-click-on-linkbutton-in-gridview/[
^]
You can even change the color of button or hide button based on condition
protected void LinkButton_Click(object sender, CommandEventArgs e)
{
LinkButton btn = (LinkButton)(sender);
string yourValue = btn.CommandArgument;
if(btn != null)
{
btn.ForeColor = System.Drawing.Color.Red;
btn.Visible = true;
}
else {
btn.ForeColor = System.Drawing.Color.Green;
btn.Visible = false;
}
}