Reputation: 329
I know this can be done using javascript but I need simplest way if there is any: I have gridview with following code @aspx page
<ItemTemplate>
<asp:HyperLink ID="idLinkBtn" runat="server" Text='<%# Eval("TR") %>' </asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("TR") %>' Visible="false"></asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("TR") %>' Visible="false" ></asp:HyperLink>
</ItemTemplate>
How can I access the hidden hyperlinks and set their text and make them visible from code behind? I tried "Find control" method but it is returning null value. Answers appreciated!
Thanks!
Upvotes: 0
Views: 2442
Reputation: 62280
You can use RowDataBound event of GridView.
For example,
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var idLinkBtn = e.Row.FindControl("idLinkBtn") as HyperLink;
// The as operator will return null if the cast fails,
// so check for null before you try to use the hyper link
if(idLinkBtn != null)
{
idLinkBtn.Visible = true;
}
}
}
Upvotes: 2