how to change gridview column name [Resolved]

Posted by Oswaldlily under ASP.NET on 10/11/2011 | Points: 10 | Views : 18409 | Status : [Member] | Replies : 3
gv.datasource="query..............."
gv.columns(0).Headertext="Employee name"
gv.databind()

when i wrote above sttement got following error.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index




Responses

Posted by: Oswaldlily on: 10/12/2011 [Member] Starter | Points: 25

Up
0
Down

Resolved
gv.headerrow.cells(0).text="Column name"

I found this more easier..

Thanks for all



Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/11/2011 [Member] Starter | Points: 25

Up
0
Down
That shows you are not adding column at design time.
Do one thing try to register RowDataBound event
and change the column name there
protected override void OnInit(EventArgs e)

{
base.OnInit(e);
gv.RowDataBound+=new GridViewRowEventHandler(gv_RowDataBound);
}
void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
if (e.Row.Cells.Count > 0)
e.Row.Cells[0].Text = "Employee Name";
}
}



Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alex_4youin on: 10/11/2011 [Member] Starter | Points: 25

Up
0
Down
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Text = "Col Name";
}
}

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response