473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To get the properties of the controls generated in runtime and placed on the Table control

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.
Nov 18 '05 #1
0 2289

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2409
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named EditStuff.ascx which reads from an xml file and loads controls to its self based on string value in xml nodes collection of the xml. There are...
6
436
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" ...
3
2775
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +201 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean...
1
1650
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled by their underlying classes (such as the TextBox control), and are not persisted by me. 2.) Unique Properties that don't map directly and are...
2
5045
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in the VS2005 designer, but at runtime, the controls are in different locations and different sizes. I have been able to restore their sizes by putting...
7
1996
by: Ronald S. Cook | last post by:
In a .NET Windows app, if I set somehting like the title of the form to "MyApp" at run-time, will that make the app run slightly slower than if I had set the title at design-time? Thanks, Ron
6
11060
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of...
15
6485
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then...
10
1848
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the dotnet textbox which is MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the property no problem. But looping through the 3rd...
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.