I have a form that is submitted to another page. The form contains a
variable number of dropdownlists within a repeater. When the form is
submitted, I need to access the values of each dropdownlist. I never
know how many dropdownlists will be present in advance.
Also, both the repeater and the dropdownlists are nested within other
controls:
ctl00$ContentPlaceHolder1$rptOptions$ctl01$dlOptions
So how can I access the dropdownlists? I am using PreviousPageType on
the page that the form is being posted to.
I thought it would be something like this:
foreach (RepeaterItem item in rptOptions.Items)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(b.Text + "<br>");
}
But I just can't get the syntax right.
Thanks
Jack
Elton W - 18 Feb 2006 23:29 GMT
Try
foreach (RepeaterItem item in rptOptions.Items)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(b.SelectedItem.Text + "<br>");
}
HTH
Elton Wang
> I have a form that is submitted to another page. The form contains a
> variable number of dropdownlists within a repeater. When the form is
[quoted text clipped - 22 lines]
>
> Jack
jjack100@gmail.com - 19 Feb 2006 23:07 GMT
I guess the real issue is that I don't know the correct syntax to
access the repeater on the second page:
The trace of the form contents shows this:
ctl00$ContentPlaceHolder1$rptOptions$ctl01$dlOptions 4
ctl00$ContentPlaceHolder1$rptOptions$ctl02$dlOptions 1
So the values are getting through. I tried this:
Repeater rpt =
(Repeater)Page.PreviousPage.FindControl("ctl00").FindControl("ContentPlaceHolder1").FindControl("dlOptions");
But I just get "Object reference not set to an instance of an object."
So how can I access those repeaters? Also, as I said before, the number
of repeaters varies.
Thanks
jjack100@gmail.com - 19 Feb 2006 23:21 GMT
I am now able to access the values when I do this:
Repeater rpt =
(Repeater)Page.PreviousPage.FindControl("ctl00").FindControl("ContentPlaceHolder1").FindControl("rptOptions");
DropDownList ddl =
(DropDownList)rpt.FindControl("ctl01").FindControl("dlOptions");
Response.Write("Here it is:" + ddl.SelectedItem.Value.ToString());
However, when I try to do this:
foreach (RepeaterItem item in rpt)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(ddl.SelectedItem.Value.ToString()); + "<br>");
}
it chokes. Any ideas?
Thanks