By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

--

Bryan Donaldson
Experience is something you don't get until just after you need it...
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.