473,602 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList in Repeater

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 of its value. Here is the code:

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItem.Altern atingItem Then
Dim ddl as DropDownList = Ctype(e.Item.Fi ndControl("ddl" ), DropDownList)

With ddl
.DataSource = ds.Tables("tbl" )
.DataValueField = "Code"
.DataTextField = "Name"
.DataBind

.SelectedValue = Ctype(e.Item.Da taItem, DataRow)("Code" ).ToString
End With
End If

If I check the DropDownList.Se lectedValue while I'm still in the above code
the SelectedValue is correctly set, but when i finally view the resulting
page all the DropDownLists controls that the Repeater has the first Item
selected... Apart from DropDownList.Se lectedValue i tried to use other
methods (i.e. .SelectedIndex) but the result is the same, the first value of
the DropDown is selected...

Thanks for you help
Shaun
Nov 19 '05 #1
1 16882
You don't need to use ItemCreated event. Simply use dropdownlist properties.
Forexample,

<asp:DropDownLi st id=ddl DataSource="<%# SourceTable %>" runat="server"
DataTextField=" Name" DataValueField= "Code" SelectedIndex=' <%#
ListIndex((Drop DownList)target ,DataBinder.Eva l( Container.DataI tem,"Code"))
%>'></asp:DropDownLis t>

SourceTable should be protected property in your page and its type is
DataTable.
ListIndex is a helper method traverse DropDownList items and compares each
item's value with second parameter of this function. And returns item's
index.

Also SelectedIndex must be given after DataSource Property. Other wise it
fails. I submit this problem as a bug. But i couldn't express myself :)))

I hope, this helps you...

--
Thanks,
Yunus Emre ALPÖZEN

"Shaun Camilleri" <sh***@holistic .com.mt> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
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 of its value. Here is the code:

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItem.Altern atingItem Then
Dim ddl as DropDownList = Ctype(e.Item.Fi ndControl("ddl" ),
DropDownList)

With ddl
.DataSource = ds.Tables("tbl" )
.DataValueField = "Code"
.DataTextField = "Name"
.DataBind

.SelectedValue = Ctype(e.Item.Da taItem, DataRow)("Code" ).ToString
End With
End If

If I check the DropDownList.Se lectedValue while I'm still in the above
code
the SelectedValue is correctly set, but when i finally view the resulting
page all the DropDownLists controls that the Repeater has the first Item
selected... Apart from DropDownList.Se lectedValue i tried to use other
methods (i.e. .SelectedIndex) but the result is the same, the first value
of
the DropDown is selected...

Thanks for you help
Shaun

Nov 19 '05 #2

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

Similar topics

0
2420
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 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 ...
7
6977
by: Darren | last post by:
Hi There, I am developing a shopping cart web application in C#. Product pricing for an item changes based on the weight of product purchased. ie: 100g=$4.95, 200g=$7.95, etc. Pricing is different for each product. When viewing the cart, I would like the the user to have the ability to select a different weight, specific to that item, which would then modify the price of that cart item.
1
2153
by: Joe Gass | last post by:
I'd like to bind some xml to a dropdownlist <engines> <engine name="test1" id="1" /> <engine name="test2" id="2" /> </engines> If I do: ddlEngines.DataSource = xmlDoc.SelectNodes("/engines/engine")
4
5103
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" runat="server"> <ItemTemplate> <%# Eval("option_name") %> <asp:DropDownList ID="dlOptions" runat="server" DataSource='<%#
1
2695
by: Jeremy | last post by:
Hello All, I have a Repeater which contains a Dynamic DropDownList within its itemtemplate. I know I have struggled with this before and I am pretty sure I had to save a bunch of crap manually to the viewstate, but does anyone know what would cause those DropDownList objects to clear out on postback. Is there a setting on the Repeater I am forgetting about? I tried tooling with EnableViewState but that did not work. The Repeater gets...
1
520
by: Eugene Anthony | last post by:
ModifyUserRegistration.aspx --------------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModifyUserRegistration.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
0
1198
by: stretch73 | last post by:
I have a repeater control with a DropDownList in the header template. I am trying to make a database call and sort the results by the selectedIndex property of the drop down. The SelectedIndexChanged event is not getting fired, feel like I've tried everything. Repeater Code ********************************************************************************************************************************** <asp:Repeater...
3
2723
by: gsauns | last post by:
Hello, I have an ASP.NET app with a DropDownList on the page, which is bound to values from a table. I have a Repeater control on the page whose displayed data is dependent on the DropDownList value selected by the user. (The DataTextField is a Datetime concatenated with a string). On the Page_Load event, if it's not a postback, I would like the DropDownList to programmatically be set to the next occurring day in the DropDownList (the...
2
3737
by: MattB | last post by:
I have a (.Net 1.1) form with a Repeater and a DropDownList in the ItemTemplate. I programmatically make the DDL Autopostback = true at runtime based on the bound data. That works - I can see the postback happen appropriately. The DropDownList looks like this: <asp:DropDownList id="ddMultiQty" OnSelectedIndexChanged="ddMultiQty_SelectedIndexChanged" runat="server"></asp:DropDownList>
0
8401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.