retrieving values from controls dynamically created in a <asp:table>

B

Bryan Donaldson

I have a table on my web form, declared like this:

<asp:table id="tblOverrides" runat="server" enableviewstate=true"
cssclass="clsTable">
<asp:tablerow cssclass="clsTblHeader">
<asp:tablecell Text="label" id="hdrLabel"></asp:tablecell">
<asp:tablecell Text="ddl" id="hdrDDL"></asp:tablecell">
</asp:tablerow>
</asp:table>
-----------------------------------------------------------------------
In a click event for a check box, I have code that looks like this, to add
label text in one column and a drop down list in another. (Btw - there are
LOTS of examples of this...)
-----------------------------------------------------------------------
dim i,j as integer
for i = 1 to 10
dim oRow as new Tablerow

oRow.EnableViewState=true

dim oLabelCell as new TableCell

oLabelCell.text = i.tostring

dim oDDLCell as new TableCell
dim oDDL as system.web.ui.webcontrols.dropdownlist

ddl.Items.clear()
ddl.Items.Add("")
for j = 0 to i
ddl.Items.Add(J.ToString)
next

oDDLCell.Controls.Add(oDDL)

oRow.Cells.Add(oLabelCell)
oRow.Cells.Add(oDDLCell)

tblOverrides.Rows.Add(oRow)
next
-----------------------------------------------------------------------

Now, in a button click event handler, I want to retrieve the selected values
from the drop down lists.

I thought something like this would work :

for n = 2 to tblOverrides.Rows.Count
dim oDDL as new system.web.ui.webcontrols.dropdownlist
oDDL = tblOverrides.Rows(n).Cells(1).Controls(0)
sum += cInt(oDDL.SelectedValue)
next

however, the tblOverrides.Rows.Count is never more than 1. What do I have
to do to be able to refer to cells I dynamically created on a later trip to
the server?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top