Solved

DropDownList in a Repeater

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

13 Experts available now in Live!

Get 1:1 Help Now