Adding Dynamic Controls to a table

Discussion in 'ASP .Net' started by srneu71@gmail.com, Nov 9, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Guest

    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.


    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, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia

    Dynamic adding rows into table problem

    Luis Esteban Valencia, Jun 23, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,371
    anan.meera
    Mar 27, 2009
  2. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    731
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
  3. Ronald
    Replies:
    2
    Views:
    850
    Robbe Morris [C# MVP]
    Jan 17, 2006
  4. opius
    Replies:
    0
    Views:
    1,182
    opius
    Jun 17, 2011
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    470
    Eidolon
    May 4, 2004
Loading...

Share This Page