473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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=""CHECKED"" />"
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.Keys.Count - 1
Response.Write("Request.Form.Key value " & Request.Form.Keys(i) & "
has value " & Request.Form.Item(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.Controls
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 2034
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.com 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=""CHECKED"" />"
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.Keys.Count - 1
Response.Write("Request.Form.Key value " & Request.Form.Keys(i) & "
has value " & Request.Form.Item(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.Controls
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
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...
4
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...
2
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...
2
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...
4
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...
3
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...
0
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...
3
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...
4
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,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.