HyperLinkField and RowDataBound in ASP.NET


To access the HyperLinkField control with the RowDataBound event of the GridView, we can use the following code (refer the column cell)

protected void gridCaseMember_RowDataBound(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow){
HyperLink myLink = (HyperLink)e.Row.Cells[0].Controls[0];

myLink.NavigateUrl = http://www.bing.com”;    }

}

http://forums.asp.net/t/1142271.aspx 

Hope it helps !

Hiding Columns in GridView when AutoGenerateColumns is True


Hi,

If we have set AutoGenerateColumns property of the GridView as true and binding it to a data source, we will not be able to remove columns from it using the Remove or RemoveAt functions of Columns.

myGridView.Columns.Remove or RemoveAt

So to remove the columns we can make use of RowDataBound event.

protected void myGridView _RowDataBound(object sender, GridViewRowEventArgs e){
// hide the second and third column
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible=false;

e.Row.Cells[2].Visible=false;}
else
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;

e.Row.Cells[2].Visible = false;}

}
Hope it helps!!