
September 25th, 2001, 12:16 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
Originally posted by : Louis-Philippe Alain (lpalain@wizh-humanz.com)Hi,I did this little function. It should help you fix your problem  rivate void BoundColumns(){_dgItemsGrid.Columns.Clear();BoundC olumn bc;foreach(DataColumn dc in ((DataView)_dgItemsGrid.DataSource).Table.Columns) {bc = new BoundColumn();bc.DataField = dc.ColumnName;bc.HeaderText = dc.Caption;bc.SortExpression = dc.ColumnName;_dgItemsGrid.Columns.Add(bc);}}You should call a similar function explicitly after setting the DataSource of your DataGrid or by catching the 'OnDataBinding' event of the DataGrid control.Let me know if this helped you!Louis-Philippe------------Brien Givens at 9/23/2001 8:52:39 AMI'm trying to create a page that will dynamically bind a table to a datagrid. I also want to specify BoundColumns for each column of the table.So, AutoGenerateColumns="false" and I can't specify the columns at design time, because I don't know how many columns I will have, etc.I can only see two ways to handle this scenario:1. Invoke a method on the DataGrid to add a column - is there such a method?2. Render code at run time - the DataGrid doesn't seem to support this.Am I making myself clear? Can anyone point me in the right direction?Here's my code:String Table = Request.QueryString["Name"];SqlConnection myConnection = ...SqlDataAdapter myCommand = new SqlDataAdapter("select * from " + Table, myConnection);DataSet ds = new DataSet();myCommand.Fill(ds, Table);MyDataGrid.DataSource = ds.Tables[Table].DefaultView;MyDataGrid.DataBind();
|