I want to create a multiple templatefield using c#. So I am trying to create in this way.
TemplateField[] ttfield = new TemplateField[10];
ttfield[0].HeaderText = "Firstname";
GridView1.Columns.Add(ttfield[0]);`
But it throws NullReferenceException
.
When I try the below code, It has created two column with the same name.
TemplateField tfield = new TemplateField();
TemplateField[] ttfield = new TemplateField[10];
for (int i = 0; i < splitSelectedColumn.Length; i++)
{
if (i < splitGroupByColumn.Length)
{
tfield.HeaderText = splitGroupByColumn[i];
GridView1.Columns.Add(tfield);
}
}
It creates two Name column, but same name.