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

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

Post by Bryan Dona » Wed, 26 Nov 2003 03:29:28

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

<asp:table id="tblOverrides" runat="server" enableviewstate=true"
<asp:tablerow cssclass="clsTblHeader">
<asp:tablecell Text="label" id="hdrLabel"></asp:tablecell">
<asp:tablecell Text="ddl" id="hdrDDL"></asp:tablecell">
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


dim oLabelCell as new TableCell

oLabelCell.text = i.tostring

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

for j = 0 to i




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)

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...

1. Need to dynamically add <ASP:Button> controls to web user control page

2. <asp:ListItem Value="0">blank choice</asp:ListItem> ?

Using this:
<asp:ListItem Value="0"> </asp:ListItem>

as long as I have a value listed and leave the area between the tags
blank, when viewed the DropDownList will show a 0 as a choice. I want it
to be blank.

I've tried doing this:
<asp:ListItem Value="0"> </asp:ListItem>

and tried this:
<asp:ListItem Value="0"> </asp:ListItem>

and putting nothing in there:
<asp:ListItem Value="0"> </asp:ListItem>

In all cases, a zero shows up as the first selection.

How can I retain the value of zero but keep the choice blank?


3. <>*<> DSP & Controls Books <>*<>

4. Do you use <table> or <asp:Table>?

5. Creating PDF files on the 3000 <<PLUG>> <<PLUG>>

6. Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls

7. how to add dynamically <tr> and <td> to a table?

8. <bam><bam><bam><bam><bam>

9. How to dynamically add <asp:> controls to a webpage?

10. Finding a Control within an <asp:table..> Control

11. multiple <td> in a repeater control <ItemTemplate> ( 2)

12. "<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk

13. ASP.NET Retrieving values from dynamically loaded user control

14. "<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk

15. <asp:table> and <colgroup> ?