I have a DataGrid in ASP.NET 2.0 with the following column in it:
<ASP:TEMPLATECOLUMN>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server"
CssClass="DataGridCommand" Target="_blank"
NavigateUrl='<%# GetPreviewURL(DataBinder.Eval(Container, "DataItem.NodeID")) %>'>
Preview Graphic
</asp:HyperLink>
</ItemTemplate>
</ASP:TEMPLATECOLUMN>
So the basic idea is to have a link in each row of the DataGrid that kicks back a pop-up image preview (referring to a data-bound column for the NodeID). This works just fine.
I am attempting to disable the links for the rows for which there is no associated image. To do this I put this in the code behind, under Page_Load:
foreach (DataGridItem dgi in this.dgNode.Items)
{
HyperLink myLink1 = (HyperLink)dgi.Cells[0].FindControl("HyperLink1");
//myLink1.Visible = false;
//if (condition for hiding links goes here...)
myLink1.Enabled = false;
this.dgNode.DataBind();
}
As you can see, I tried setting the visible property to false, but that didn't work. I tried setting enable to false, it didn't work either. And then I tried databinding the DataGrid again -- doesn't work. The links continue to function normally.
Does anyone know why this doesn't work, what can be done to make it work, and if it's fundamentally flawed, an alternate solution? I'm looking to either grey out the link for certain rows, or hide it so that it can't be clicked.
Thanks!