Hi All
I am developing a site using ASP.Net
I want to develop a site that generates forms ( textbox,check boxes etc) automatically ie is from database itself depending on the no of rows in the table in database. That is to get as many textboxes and checkboxes as there are rows in table
What I am doing right now is creating new text box, checkboxes etc in the code and then adding them to the cells and rows of the table control.
This all works fine.
The problem comes when I have to extract data from the form and insert into databse table.
How do I get the properties of the controls generated in runtime and placed on the Table control?
here are pieces of my code.
Public rows, textCount, chkCount, cmbCount As Integer
Public arr(,) As String //An array to store ids of auto generated controls
//To create forms
Dim locType, forType As String
locType = cmbSelect.Selec tedItem.Value
forType = cmbSelect1.Sele ctedItem.Value
Dim con As New OdbcConnection( ConfigurationSe ttings.AppSetti ngs("conStr"))
Dim da As New OdbcDataAdapter ("select * from TEST_FORMAT where LType='" + locType + "'and FORMATTYPE='" + forType + "' ORDER BY PRINTID", con)
Dim ds As New DataSet()
da.Fill(ds)
Dim i, col As Integer
rows = ds.Tables(0).Ro ws.Count
ReDim arr(rows, 3)
For i = 0 To rows - 1
Dim row As New TableRow()
Dim cChkBox As New TableCell()
Dim cLab As New TableCell()
Dim cTxtBox As New TableCell()
Dim cPID As New TableCell()
Dim PrintId As New System.Web.UI.W ebControls.Labe l()
Dim l As New System.Web.UI.W ebControls.Text Box()
Dim parent, PID As String
PID = ds.Tables(0).Ro ws(i).Item(0).T oString
arr(i, 0) = PID
parent = ds.Tables(0).Ro ws(i).Item("PAR ENTID").ToStrin g
PrintId.Text = ds.Tables(0).Ro ws(i).Item("PRI NTID")
PrintId.BackCol or = Color.Cornsilk
cPID.Controls.A dd(PrintId)
row.Cells.Add(c PID)
If Not parent = "root" Then //making check box only for sub points and not for main Points
Dim chkBox As New Web.UI.WebContr ols.CheckBox()
Response.Write( chkBox.GetType. ToString)
chkBox.ID = "chkBox" & i
arr(i, 1) = chkBox.ID
cChkBox.Control s.Add(chkBox)
row.Cells.Add(c ChkBox)
chkCount += 1
chkBox.EnableVi ewState = True
Else //if it is main point no need of check box
cChkBox.Control s.Add(New System.Web.UI.W ebControls.Labe l())
arr(i, 1) = "NULL"
row.Cells.Add(c ChkBox)
End If
l.Text = ds.Tables(0).Ro ws(i).Item("DES CRIPTION")
l.TextMode = TextBoxMode.Mul tiLine
l.ForeColor = Color.Black
l.Rows = 2
l.Columns = 40
l.ReadOnly = True
l.BorderColor = Color.Empty
cLab.Controls.A dd(l)
row.Cells.Add(c Lab)
If Not parent = "root" Then
If Ques = 1 Then
Dim txtBox As New Web.UI.WebContr ols.TextBox()
Response.Write( txtBox.GetType. ToString)
txtBox.TextMode = TextBoxMode.Mul tiLine
txtBox.Rows = 2
txtBox.Columns = 40
txtBox.ID = "txtBox" & i
arr(i, 2) = txtBox.ID
cTxtBox.BorderS tyle = BorderStyle.Ins et
cTxtBox.Control s.Add(txtBox)
row.Cells.Add(c TxtBox)
textCount += 1
ElseIf Ques = 2 Then
Dim cmb As New Web.UI.WebContr ols.DropDownLis t()
Response.Write( cmb.GetType.ToS tring)
cmb.Items.Add(" YES")
cmb.Items.Add(" NO")
cmb.ID = "cmb" & i
arr(i, 2) = cmb.ID
cTxtBox.BorderS tyle = BorderStyle.Ins et
cTxtBox.Control s.Add(cmb)
row.Cells.Add(c TxtBox)
cmbCount += 1
End If
Else
arr(i, 2) = "NULL"
End If
// To access properties of controls generated at runtime
Function iterateReadCont rols(ByVal par As Control)
Dim c As Control
Dim var As String
For Each c In par.Controls
var = c.GetType.ToStr ing
Response.Write( c.GetType.ToStr ing)
Response.Write( "*")
' If c.GetType.ToStr ing.Equals("Sys tem.Web.UI.WebC ontrols.Table") Then
'Dim t As New Table()
If c.Controls.Coun t > 0 Then
iterateReadCont rols(c)
End If
If c.GetType.ToStr ing.Equals("Sys tem.Web.UI.WebC ontrols.CheckBo x") Then
chkCount += 1
ElseIf c.GetType.ToStr ing.Equals("Sys tem.Web.UI.WebC ontrols.TextBox ") Then
textCount += 1
ElseIf c.GetType.ToStr ing.Equals("Sys tem.Web.UI.WebC ontrols.DropDow nList") Then
cmbCount += 1
End If
Next
End Function
i would be very grateful if anyone can guide me with this
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.