473,381 Members | 1,446 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,381 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 2396

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.