Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

accessing datalist in repeater

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jjack100@gmail.com - 18 Feb 2006 01:15 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.