hi
i'm trying to dynamically add columns to my gridview control.

i tried this code:

BoundColumn col = new BoundColumn();
col.DataField = myDataTable.Columns[0].ColumnName;
col.HeaderText = "last exit time";
col.DataFormatString = "{0:mm-dd-yyyy}";
GridView1.Columns.Add(col);

the datafied property is taken from datatable which will be the source of the gridview.
the build gives me an error "cannot convert from bound column to datacontrolfield".
i tryed to create new datacontrolfield but i dont know which object to create ?
what is the right way to dynamically add bound columns to gridview ?

Hi,
try to use :
BoundField bf = new BoundField(); rather than BoundColumn
I am able to add columns to gridview dynamically using BoundField.
And also I am not sure about "DataFormatString".

First try to use BoundField.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.