The datagrid server control provides a property named AutoGenerateColumns
that would allow the grid to display any number of columns that are on the
datatable.
http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx
You can make the datagrid editable by adding an EditCommandColumn
http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx
Another alternative is to turn the AutoGenerateColumns to false and then
compose the columns programmatically during databinding like this:
private void dgItems_DataBinding(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgItems.DataSource;
for( int c=1; c<dt.Columns.Count; c++ )
{
BoundColumn bc = new BoundColumn();
bc.DataField = dt.Columns[c].ColumnName;
bc.HeaderText = dt.Columns[c].ColumnName;
dgItems.Columns.Add( bc );
}
}
--
HTH,
Phillip Williams
http://www.societopia.net http://www.webswapp.com
"ER" wrote:
Hi,
I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?
Any help would be appreciated!
ER