Question

I have gridview with autogenerated columns.I have added a column dynamically in the row databound event.

     if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TableCell cell1 = new TableCell();
        e.Row.Cells.Add(cell1);
    }

       // to add header
    else
    {
        TableCell cell1 = new TableCell();
        cell1.Text = "<span style='font-weight:bold'>NAME";
        e.Row.Cells.Add(cell1);
    }   

This column gets added at the end. I want to add this column in the index 2.

Any one can help me please? Thanks in Advance.

Was it helpful?

Solution

Use AddAt(int index, TableCell cell) instead

Example:

e.Row.Cells.AddAt(2, cell1);

Hope this will help !!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top