Adding A Databound Column Dynamically in DataGrid
i am trying to add column dynamically in Datagrid.
now after creating boundcolumn whenever trying to add it in Datagrid it gives me error of "Object reference not set to an instance of an object." what is wrong with this code?Please Tell me thanks in advance.
DataSet ds = new DataSet();
ds = getDataset(); // here Dataset has two column named "ID" and "Name"
BoundColumn[] name = new BoundColumn[12]; // Array of Bound Column
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
name[i].HeaderText = Convert.ToString(ds.Tables[0].Rows[i]["Name"]); //Here error Comes
name[i].DataField = Convert.ToString(ds.Tables[0].Rows[i]["Name"]);
DataGrid4.Columns.Add(name[i]);
}
|