Solved

DropDownList in a Repeater

Posted on 2006-07-11
4
300 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

21 Experts available now in Live!

Get 1:1 Help Now