Ask a Question related to ASP Components, Design and Development.
-
Brian Lorraine #1
programmatically adding controls to template column
Could someone help me figure out how to programmatically create a simple
LABEL in a template column? I have a GridVIEW that needs to have a dynamic
number of columns which is simple enough for me :) but the tricky part is
trying to add data inside the column. I tried intuitively figuring out what
to do by working my way backwards from the templatefield object and then
through the controls collection and the datacontrolfields collection, etc
etc, but I think I'm heading in the wrong direction. Can someone set me
straight?
For simple argument's sake, let's just say I'm trying to add a label that
says "BLA" in the main (non edit mode) template.
I found one MSDN article dealing with DataControlFieldCells, but it only
gave a tiny tiny snippet of code and wasn't really much help. Here's my code.
It's pretty basic:
Dim zzz As Integer
Dim headtext As String
''' Create columns dynamically
For zzz = 0 To (countcols - 1)
''' Testview tells me how many columns to add
''' Don't worry about where this info comes from
testrow = testview(zzz)
Dim newcol As New TemplateField
Dim cfield As New Label
cfield.Text = "BLA"
' No idea what to do here. This is where I need help
' How do I add CFIELD as a control inside of NEWCOLS's
' ITEMTEMPLATE class?
' This formats the columns just fine.
headtext = testrow("StatusName")
newcol.HeaderText = headtext
newcol.HeaderStyle.BackColor = Drawing.Color.Aqua
' Add the column.. works fine
GridView1.Columns.Add(newcol)
newcol = Nothing
Next zzz
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''
GridView1.DataBind()
Brian Lorraine Guest
-
Adding Controls to a Web Forms Page Programmatically
Hi I'm having some trouble adding a user control to my webform programmatically. I've done this before, but not for some time. The control was... -
Template Column Controls DataBinding
Hi I have designed a datagrid control that is inherited from the base datagrid control. The main problem I have is when the grid is in edit mode... -
Adding validation controls programmatically
I am creating a server control that adds web controls (i.e. textboxes, etc) to a form. I use HtmlTable to build the table and insert the controls. ... -
Accessing controls in template column with JavaScript
Hi Guys & Gals, Is it possible to access controls (e.g. a CheckBox) within a template column in a datagrid with JavaScript? I would like to... -
how to Add different controls(textBox,DropDownList or some ) in the same column,based upon the value in the previous column (Say second Colum which contain dropdown with some values) ?
I am new to ASP.NET. I am facing problem with datagrid. I will explain prob now. In the datagrid the first column is name in the second...



Reply With Quote

