471,339 Members | 1,231 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Setting the SelectedItem of a dropdownlist inside a repeater

I have a dropdownlist which lives inside of a repeater. The repeater
accepts user input via textboxes and the aforementioned dropdownlist.
The repeater accepts phone numbers and allows for an arbitrary number
of empty rows to be added to it.
So, if a user knew in advance that they wanted to add 3 phone numbers,
they can type the nuber '3' in a textbox (outside the repeater)
and click a button (also outside of a repeater), and 3 new empty rows
will appear in the repeater. The code that does that looks
like this:

For Each objRepeaterItem As RepeaterItem In rptAgencyPhoneList.Items
Dim ddlPhoneCategory As DropDownList =
DirectCast(objRepeaterItem.FindControl("ddlPhoneCa tegory"),

'Create a Phone object
Dim objPhone As New
Phone(ConvertExpectedInteger(DirectCast(objDataGri dItem.FindControl("lblPkPhone"),
With objPhone
.Number =
DirectCast(objDataGridItem.FindControl("txtAdditio nalVoice"),
.TTYNumber =
DirectCast(objDataGridItem.FindControl("txtAdditio nalTTY"),
.Category =
ConvertExpectedInteger(ddlPhoneCategory.SelectedVa lue)
.CategoryName =
ConvertExpectedString(ddlPhoneCategory.SelectedIte m.Text)
End With

'Add the existing items to the collection

'Add the requested blank rows to the collection
For i As Integer = 1 To rowsToAdd
Dim objPhone As New Phone

After I have added the information from the repeater into a collection,
I bind to the repeater
rptAgencyPhoneList.dataSource = objPhoneCollection

Then the repeater's item_created event takes over, as shown below.

'eliminate headers, footers, seperators....
If e.Item.ItemType = ListItemType.AlternatingItem Or
e.Item.ItemType = ListItemType.Item Then
'Populate the phone category drop down list
Dim ddlPhoneCategory As DropDownList =
DirectCast(e.Item.FindControl("ddlPhoneCategory"), DropDownList)
Dim objPhoneCategoryList As ListItemCollection =
For Each item As ListItem In objPhoneCategoryList

'If a phone number exists, then select the appropriate category type
in the drop down list
If ConvertExpectedInteger(DataBinder.Eval(e.Item.Data Item,
"Category")) > 0 Then

ddlPhoneCategory.Items.FindByValue(DataBinder.Eval (e.Item.DataItem,
"Category").ToString).Selected = True
End If
End If

After all of this is finished, the page is displayed. However the
dropdownlist's selected item is always set to the first item in the
no matter what. Also, If I add an Else statement to the last IF..End IF
a error message is thrown stating that a dropdownlist can have
only one selected item.

Does anyone have any ideas?

Jul 21 '05 #1
0 2281

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Shaun Camilleri | last post: by
9 posts views Thread by james.e.coleman | last post: by
4 posts views Thread by jjack100 | last post: by
1 post views Thread by Eugene Anthony | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.