vignesh t

vignesh t

  • NA
  • 63
  • 20k

Disable hyperlink if cell value null in gridview

Jan 16 2018 3:14 AM
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)