Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have succeed to do download link in my system. But, I cannot figure out how to different it if there is null value in the database. Please help me on how to differentiate or give me some idea.


What I have tried:

<asp:LinkButton ID="lnkDownload" runat="server" Text="Download Here" OnClick="DownloadFile" CommandArgument='<%# Eval("id")%>'></asp:LinkButton>
Posted
Updated 5-Jan-21 19:43pm

1 solution

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)//Check for not null
        {
            Response.Redirect("YourPage.aspx?IdPassed=" + e.CommandArgument.ToString());//Do what ever you want
        }
    }

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;    
    }
}
 
Share this answer
 
Comments
Maciej Los 6-Jan-21 5:54am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900