5
Answers

Disable hyperlink if cell value null in gridview

Photo of vignesh t

vignesh t

7y
146
1
I have a grid where columns are populated dynamically. I have a column called ID which will have hyperlink enabled and hyperlinks needs to be disabled if cells value is null or empty.
 
Code: 
 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
string strHeaderRow = GridView1.HeaderRow.Cells[i].Text;
if (strHeaderRow == "ID")
{
string strMktURL = "http://www.address.com";
HyperLink hlColumns = AddHyperLink(e.Row.Cells[i], strMktURL);
}
}
}
}
protected HyperLink AddHyperLink(TableCell cell, string strURL)
{
HyperLink hl = new HyperLink();
hl.Text = cell.Text;
hl.Font.Underline = true;
hl.Target = "_blank";
hl.NavigateUrl = strURL;
hl.Attributes.Add("style", "color:Black;");
cell.Controls.Add(hl);
return hl;
}
 
Please suggest how this can be achieved. 

Answers (5)

1
Photo of Joginder Banger
NA 10k 490.8k 8y
Good job keep it up..
0
Photo of ketan lohpatre
NA 35 343 8y
I am using firefox latest Version (51.0.1)
 thanks but
i have fixed it by adding custom breakpoint
just after GridView Control now it works ...
 ex:-
 
</asp:GridView>
<script type="text/javascript">
$('#grd').footable({
     breakpoints: {
     phoneP: 290,
     phoneL: 530,
     tabletP: 768,
     tabletL: 992
    }
});
</script> 
 
Thanks ...
 
 
0
Photo of Joginder Banger
NA 10k 490.8k 8y
which browser you are using. Actually this type of problem am faced many times, its seems to browser issue. please use latest browser.