| | |
Controls in GridView
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 47
Reputation:
Solved Threads: 0
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
...assuming you are using VB for coding
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
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.
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.
•
•
Join Date: Jun 2006
Posts: 22
Reputation:
Solved Threads: 0
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?
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?
![]() |
Similar Threads
- MultiLine TextBoxes in GridView edit mode (ASP.NET)
- How to encapsulate a GridView in a <fieldset> tag? (ASP.NET)
- Getting values from GridView Controls (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Cannot load newly created profile
- Next Thread: How to add games to my site?
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dropdownlist dropdownmenu dynamic edit embeddingactivexcontrol expose findcontrol flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list login menu microsoft mono mssql multistepregistration nameisnotdeclared numerical objects order panelmasterpagebuttoncontrols problem ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql sqlserver2005 ssl suse textbox tracking unauthorized validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment webservice wizard xml youareanotmemberofthedebuggerusers






