Hi all,
I am trying to add columns to my grid programmatically. It works OK with 1 column, but more than 1 throw an error about multiple controls with the same ID. I'm using the below code:
// Add columns programmatically
GridBoundColumn boundColumn;
int ii = 0;
int ij = 0;
foreach (DataRow row in dt.Rows)
{
// We only want to generate columns off the first row
if (ii>0) continue;
// Create the new column collection in our loop
boundColumn = new GridBoundColumn();
foreach (DataColumn col in dt.Columns)
{
// Increment to pass the first columns
ij++;
// We don't want the first column because it's our identity (ID) column
if (ij == 1) continue;
boundColumn.DataField = col.ToString();
boundColumn.HeaderText = col.ToString();
// Add the column to our grid
gvLUs.MasterTableView.Columns.Add(boundColumn);
}
ii++;
}
// Bind the data to the grid
gvLUs.DataBind();
I've checjed and the text from col.ToString() is different. The error is balking about an ID from the second column being added. The error is as the page is rendered.
Any ideas?
Thanks!