Controls in GridView

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 22
Reputation: infinity4ever is an unknown quantity at this point 
Solved Threads: 0
infinity4ever infinity4ever is offline Offline
Newbie Poster

Controls in GridView

 
0
  #1
Jul 19th, 2006
hi

how can i add controls to a gridview at runtime? anyone knows?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: Controls in GridView

 
0
  #2
Jul 19th, 2006
I think you can do this in the same way that you would any table-related collection. If you simply want to add a control, you user GridView1.Rows(y).Cells(x).Controls.Add(ControlToAdd) If you want to add a complete row of controls, you can create a table row object at runtime: Dim x as new TableRow and similarly create table cells. Then you will add each table cell to the row: TR.Cells.Add(TC) (TR = table row/TC = table cell). Finally, you would add the row to the gridview. GridView1.Rows.Add(TR)

...assuming you are using VB for coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 22
Reputation: infinity4ever is an unknown quantity at this point 
Solved Threads: 0
infinity4ever infinity4ever is offline Offline
Newbie Poster

Re: Controls in GridView

 
0
  #3
Jul 23rd, 2006
hi ChimpusDupus

am using vb.net.. i didnt try your method yet but i will and i'll tell you the results

thank you very much
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 22
Reputation: infinity4ever is an unknown quantity at this point 
Solved Threads: 0
infinity4ever infinity4ever is offline Offline
Newbie Poster

Re: Controls in GridView

 
0
  #4
Jul 26th, 2006
it didnt work i dont know why.. always give me an error out of range whats the problem?
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Controls in GridView

 
0
  #5
Jul 26th, 2006
Out of range means you are trying to access an item in a collection that doesn't exist.

Take Cells for example, Cells(0) is the first cell in the Cells collection, if there is only 1 cell in the collection and you try referencing Cells(1) then you get an out of range error.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 22
Reputation: infinity4ever is an unknown quantity at this point 
Solved Threads: 0
infinity4ever infinity4ever is offline Offline
Newbie Poster

Re: Controls in GridView

 
0
  #6
Jul 29th, 2006
Finally its done.. PARTIALLY

seems like there is one problem left... can anyone help me with?

i did this:

Dim LB as new Label
Dim TR as new TableRow
Dim TC as new TableCell
Dim DT as new Data.DataTable
Dim DC as new Data.DataColumn

LB.Text = "Hello"
TC.Controls.Add(LB)
TR.Cells.Add(TC)
DC.ColumnName = "Labels"
DT.Columns.Add(DC)
DT.Rows.Add(TR)
GridView.DataSource = DT
GridView.DataBind()


this is the code... but when i click a button to run it the grid view display a column with the name "Labels" as i want but in the cell it only writes this:

System.Web.UI.WebControls.TableRow

instead of displaying the label i created

whats the problem? anyone knows?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 22
Reputation: infinity4ever is an unknown quantity at this point 
Solved Threads: 0
infinity4ever infinity4ever is offline Offline
Newbie Poster

Re: Controls in GridView

 
0
  #7
Jul 29th, 2006
all i want is to load that label into the grid view
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC