---
title: "How can i add a column name to my Grid?"  
description: "How can i add a column name to my Grid?"  
author: "mohan kumar"  
published: 2011-12-21  
updated: 2011-12-22  
canonical: https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How can i add a column name to my Grid?

How can i add a [column name](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) to my Grid when i [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) my grid [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) from a list of [array values](https://www.mindstick.com/forum/159317/merge-json-array-values-across-multiple-rows-in-mysql)?\
This is my code snippet..\
\

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page {    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            loadMyGrid();        }    }    public void loadMyGrid()    {        string[] stuff = new string[] {"Mohan","Arul Prakash","Lakshman","Ravindran","Senthil","Nagaraj","Bala","Suresh","Ashok" };                //GridView1.Columns[0].HeaderText = "My Customized Grid Control";        GridView1.DataSource = stuff;        GridView1.DataBind();    }}
```

\
When my above code is executed, it is displaying the following error.\
"[Index](https://www.mindstick.com/blog/198/index-in-sql-server) was out of range. Must be non-negative and less than the size of the collection.\
[Parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) name: index"\
Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) there to help me???\
\
Thanks in advance...

## Replies

### Reply by Anonymous User

Hi Mohan Kumar,

I had modified your code which works as you want..

Please check this code and let me know if further any problem.

```
public partial class _Default : System.Web.UI.Page

{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            loadMyGrid();        }    }    public void loadMyGrid()    {        string[] stuff = new string[] { "Mohan", "Arul Prakash", "Lakshman", "Ravindran", "Senthil", "Nagaraj", "Bala", "Suresh", "Ashok" };   GridView1.DataSource = stuff;  GridView1.DataBind();  }  protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)  {  if (e.Row.RowType == DataControlRowType.Header)  {e.Row.Cells[0].Text = "My Customized Grid Control";  }

}

}
```


---

Original Source: https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
