forum

Home / DeveloperSection / Forums / How can i add a column name to my Grid?

How can i add a column name to my Grid?

mohan kumar 2469 21-Dec-2011
How can i add a column name to my Grid when i populate my grid control from a list of array values?
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 was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Can anyone there to help me???

Thanks in advance...

c# c# 
Updated on 22-Dec-2011
Having around 5 Years experience in .NET domain.

Can you answer this question?


Answer

1 Answers

Liked By