Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding Dynamic Controls to a table

Reply
Thread Tools

Adding Dynamic Controls to a table

 
 
srneu71@gmail.com
Guest
Posts: n/a
 
      11-09-2006
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

 
Reply With Quote
 
 
 
 
srneu71@gmail.com
Guest
Posts: n/a
 
      11-09-2006
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.


http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic table with dynamic controls and mySql ... opius ASP .Net 0 06-17-2011 08:55 AM
Dynamic adding rows into table problem Luis Esteban Valencia ASP .Net 1 03-27-2009 07:20 AM
Dynamic Controls created by Dynamic Controls Ronald ASP .Net 2 01-17-2006 12:44 AM
Adding dynamic LinkButton to dynamic table =?Utf-8?B?QkxpVFpXaU5H?= ASP .Net 0 07-27-2005 12:21 AM
Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls Denny Smolinski via .NET 247 ASP .Net Web Controls 1 05-04-2004 09:15 PM



Advertisments