Solved

DropDownList in a Repeater

Posted on 2006-07-11
4
307 Views
Last Modified: 2008-02-26
Hello All

I have a repeater with a dropdown list.("ddlOwner")

I am trying to access the dropdown on the Sub Page_Load with this
rptEditProject.Items(0).FindControl("ddlOwner")

I can find it if it is in a Sub other than the Sub Page_Load.

Is there something I have to change to access it on the page loading?

Dim ddlOwner As DropDownList = rptEditProject.Items(0).FindControl("ddlOwner")

gives the the following error:
"Index was out of range. Must be a non negative and less than the size of the collection"

many thanks

Don
0
Comment
Question by:donaldcroswell
4 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 17079545
try this
Dim ddlOwner As  DropDownList = CType(Me.rptEditProject.Items(0).FindControl("ddlOwner"), DropDownList)

HTH
0
 
LVL 1

Accepted Solution

by:
DefaultUser earned 500 total points
ID: 17079569
If your repeator is being bounded, you need to rebind it before you can access the Items collection. Now if you do the rebinding in the PageLoad the viewstate will only be restored after the PageLoad event and hence all the changes made by the user to the drop down won't be available, so try rebinding the repeater in a method and call that method from the page_init. This should solve the problem.

DU
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 17079710
"Now if you do the rebinding in the PageLoad the viewstate will only be restored after the PageLoad event"....

One question here DefaultUser...
doesn't the LoadViewState fire before the Page_Load?
or am i terribly wrong?
0
 

Author Comment

by:donaldcroswell
ID: 17086576
Thanks Guys

I added the following code before to bind the data and it worked.

rptEditProject.DataBind()

I really appreciate the help!

Don
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now