471,119 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 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 1928
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Punisher | last post: by
2 posts views Thread by D Sheldon | last post: by
2 posts views Thread by Tim Marsden | last post: by
4 posts views Thread by Bas Groeneveld | last post: by
3 posts views Thread by Tyler Carver | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
3 posts views Thread by Ankit Aneja | last post: by

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.