.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 23rd, 2001, 10:52 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
Dynamically binding DataGrid

Originally posted by : Brien Givens (brgivens@hotmail.com)I'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();

Reply With Quote
  #2  
Old September 25th, 2001, 12:16 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
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 problemrivate 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();

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Dynamically binding DataGrid


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway