473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 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"),
DropDownList)

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

'Add the existing items to the collection
objPhoneCollection.Add(objPhone)

'Add the requested blank rows to the collection
For i As Integer = 1 To rowsToAdd
Dim objPhone As New Phone
objPhoneCollection.AddEmptyItem(objPhone)
Next
Next

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

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 =
getPhoneCategoryList()
For Each item As ListItem In objPhoneCategoryList
ddlPhoneCategory.Items.Add(item)
Next

'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
list
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 2400

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
0
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i...
1
by: Shaun Camilleri | last post by:
Hi all, I am creating a DropDownList in a RepeaterControl. After the Repeater is DataBound in the ItemCreated event (of the Repeater) I bind the DropDownList to a Table and then try to select one...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
0
by: Reza Nabi | last post by:
Dear All: Banckgroud: I have a datagrid which lives inside a repeater. Which is working fine. What i need is to dyanamically set the column width of the grid (which lieves inside the repeater)....
3
by: Ben Dewey | last post by:
Hey everyone, I have a wierd issue i can't seem to find out whats going on. I have a Control for a Shopping Cart Merchant Page called OrderStatus.ascx Inside that control there is a Repeater...
4
by: jjack100 | last post by:
I have a DropDownList that is nested inside a Repeater. The datasource of the DropDownList is declared in the aspx, not the codebehind. So we have this: <asp:Repeater ID="rptOptions"...
0
by: kamaumalone | last post by:
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...
1
by: Eugene Anthony | last post by:
ModifyUserRegistration.aspx --------------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModifyUserRegistration.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.