472,989 Members | 3,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 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 2014
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.