473,796 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Dynamic Controls to a table

I have a project that requires a dynamically generated matrix table.
The table is setup with 4 quadrants (N,S,E,W) with checkboxes to "link"
the data in adjacent quadrants. The table has to be able to grow &
shrink according to the number of items in each quadrant.

I have coded the table as a user control in vb.net. My question is on
how to retrieve the data out of the table on a post back. I have tried
adding check boxes as straight html like:

For yCnt = 1 To actRows
Dim xRow As New TableRow
For xCnt = 1 To actCols
Dim xCell As New TableCell
.... logic to determine cell area ...
xCell.Text = "<input id=""chkNE" & xCnt & "|" & yCnt & """
type=""checkbox "" checked=""CHECK ED"" />"
xCell.ID = "td" & cellCnt
xRow.Cells.Add( xCell)
Next
xRow.ID = "tr" & yCnt
tblXmatrix.Rows .Add(xRow)
Next

I tried pulling out the data with the request.forms collection but all
I get is view state forms using:
Dim i As Integer
For i = 0 To Request.Form.Ke ys.Count - 1
Response.Write( "Request.Form.K ey value " & Request.Form.Ke ys(i) & "
has value " & Request.Form.It em(Request.Form .Keys(i)) & "<br/>")
Next
I have also tried putting in the controls like:
For yCnt = 1 To actRows
Dim xRow As New TableRow
For xCnt = 1 To actCols
Dim xCell As New TableCell
.... logic to determine cell area ...
Dim chkBoxNW As New CheckBox
chkBoxNW.ID = "chkNW" & xCnt & "|" & yCnt
xCell.Controls. Add(chkBoxNW)
xCell.ID = "td" & cellCnt
xRow.Cells.Add( xCell)
Next
xRow.ID = "tr" & yCnt
tblXmatrix.Rows .Add(xRow)
Next

Using the following code I can "see" the controls, but the checked
value is always false regardless of what is selected before postback.

Dim myRow As Control
For Each myRow In tblXmatrix.Cont rols
Response.Write( "row =" & myRow.ID & "<br>")
Dim myCell As Control
For Each myCell In myRow.Controls
Response.Write( "cell =" & myCell.ID & "<br>")
Dim myChk As CheckBox
For Each myChk In myCell.Controls
Response.Write( "ctl =" & myChk.ID & "=" & myChk.Checked & "<br>")
Next
Next
Next

I'm fairly new to asp.net, so there has to be something simple I'm
missing here.
Thanks
-srneu71

Nov 9 '06 #1
1 2052
Nevermind, My issue was a page lifecycle issue. I used the 2nd method
and checked for a postback in the Page_PreRender and got all the
correct values.
sr*****@gmail.c om wrote:
I have a project that requires a dynamically generated matrix table.
The table is setup with 4 quadrants (N,S,E,W) with checkboxes to "link"
the data in adjacent quadrants. The table has to be able to grow &
shrink according to the number of items in each quadrant.

I have coded the table as a user control in vb.net. My question is on
how to retrieve the data out of the table on a post back. I have tried
adding check boxes as straight html like:

For yCnt = 1 To actRows
Dim xRow As New TableRow
For xCnt = 1 To actCols
Dim xCell As New TableCell
.... logic to determine cell area ...
xCell.Text = "<input id=""chkNE" & xCnt & "|" & yCnt & """
type=""checkbox "" checked=""CHECK ED"" />"
xCell.ID = "td" & cellCnt
xRow.Cells.Add( xCell)
Next
xRow.ID = "tr" & yCnt
tblXmatrix.Rows .Add(xRow)
Next

I tried pulling out the data with the request.forms collection but all
I get is view state forms using:
Dim i As Integer
For i = 0 To Request.Form.Ke ys.Count - 1
Response.Write( "Request.Form.K ey value " & Request.Form.Ke ys(i) & "
has value " & Request.Form.It em(Request.Form .Keys(i)) & "<br/>")
Next
I have also tried putting in the controls like:
For yCnt = 1 To actRows
Dim xRow As New TableRow
For xCnt = 1 To actCols
Dim xCell As New TableCell
.... logic to determine cell area ...
Dim chkBoxNW As New CheckBox
chkBoxNW.ID = "chkNW" & xCnt & "|" & yCnt
xCell.Controls. Add(chkBoxNW)
xCell.ID = "td" & cellCnt
xRow.Cells.Add( xCell)
Next
xRow.ID = "tr" & yCnt
tblXmatrix.Rows .Add(xRow)
Next

Using the following code I can "see" the controls, but the checked
value is always false regardless of what is selected before postback.

Dim myRow As Control
For Each myRow In tblXmatrix.Cont rols
Response.Write( "row =" & myRow.ID & "<br>")
Dim myCell As Control
For Each myCell In myRow.Controls
Response.Write( "cell =" & myCell.ID & "<br>")
Dim myChk As CheckBox
For Each myChk In myCell.Controls
Response.Write( "ctl =" & myChk.ID & "=" & myChk.Checked & "<br>")
Next
Next
Next

I'm fairly new to asp.net, so there has to be something simple I'm
missing here.
Thanks
-srneu71
Nov 9 '06 #2

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

Similar topics

3
1704
by: Punisher | last post by:
I'm adding checkbox controls to a table dynamically when the form loads for the first time. When a postback occurs, the controls are not maintained in the table. How do I get them to retain without having re-add them again.
4
5483
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
2
4858
by: D Sheldon | last post by:
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. Now I want to add validators to the textbox. Here is the code that I am using bool lastnamerequired=false public bool LastNameRequire get{return lastnamerequired; set{lastnamerequired = value; if(lastnamerequired
2
2112
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the controls, and populate the dropdowns etc, I use addhandler to define delegates to capture events raised by the controls. I store these controls in a hashtable.
4
2501
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
3
1812
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a postback. The main question would be this: Why does this work for maintaining state after a postback for dynamic controls: myText = new Label(); myText.ID = "myText";
0
2408
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
3
2346
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
4
2552
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel, and lets say I have a button as a trigger which runs a function in my code behind to add a textbox to the updatePanel, when the form is submitted does this control actually "exist" as such on the
0
9685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.