473,385 Members | 1,341 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,385 software developers and data experts.

Can't set SelectedValue property on ASP.NET DropDown

Hi there,

I am having a problem with an ASP.NET DropDown list - whenever I set the
SelectedValue (or SelectedIndex) property, when the page displays, only the
first item is ever selected. This is a databound dropdown, and I have
executed the DataBind() method prior to trying to set the selectedvalue
property. Both are being done in the Page_Load method, and only if the page
is not posting back.

Any ideas would be appreciated.

-Steven
Nov 15 '05 #1
3 18724
try using the FindByValue method on the items collection and then set the
Selected property to true:

ddlMyList.Items.FindByValue("stringforselectedvalu e").Selected = true;

hth

"Steven" <ms******@berkovitz.org> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Hi there,

I am having a problem with an ASP.NET DropDown list - whenever I set the
SelectedValue (or SelectedIndex) property, when the page displays, only the first item is ever selected. This is a databound dropdown, and I have
executed the DataBind() method prior to trying to set the selectedvalue
property. Both are being done in the Page_Load method, and only if the page is not posting back.

Any ideas would be appreciated.

-Steven

Nov 15 '05 #2
I've tried that too..

my code is as follows (BindData() gets called from the Page_Load method):

private void BindData()
{
lstAssociations.DataSource =
BusinessLogic.ProductAssociations.Instance().GetAs sociations();
lstAssociations.DataTextField = "DisplayText";
lstAssociations.DataValueField = "AssociationID";
lstAssociations.DataBind();

lstAssociations.SelectedValue = Request.QueryString["associationID"];

// Also tried
//
lstAssociations.Items.FindByValue(Request["associationID"].ToString().Trim()
).Selected = true;
}

Any ideas?

"Giri" <gt******@prologis.com> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
try using the FindByValue method on the items collection and then set the
Selected property to true:

ddlMyList.Items.FindByValue("stringforselectedvalu e").Selected = true;

hth

"Steven" <ms******@berkovitz.org> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Hi there,

I am having a problem with an ASP.NET DropDown list - whenever I set the
SelectedValue (or SelectedIndex) property, when the page displays, only

the
first item is ever selected. This is a databound dropdown, and I have
executed the DataBind() method prior to trying to set the selectedvalue
property. Both are being done in the Page_Load method, and only if the

page
is not posting back.

Any ideas would be appreciated.

-Steven


Nov 15 '05 #3
For anyone who is interseted, the problem was that I was setting the
selectedvalue property AFTER binding the data - it has to be set before hand
(before you set the datasource and call DataBind())
"Steven" <ms******@berkovitz.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I've tried that too..

my code is as follows (BindData() gets called from the Page_Load method):

private void BindData()
{
lstAssociations.DataSource =
BusinessLogic.ProductAssociations.Instance().GetAs sociations();
lstAssociations.DataTextField = "DisplayText";
lstAssociations.DataValueField = "AssociationID";
lstAssociations.DataBind();

lstAssociations.SelectedValue = Request.QueryString["associationID"];

// Also tried
//
lstAssociations.Items.FindByValue(Request["associationID"].ToString().Trim() ).Selected = true;
}

Any ideas?

"Giri" <gt******@prologis.com> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
try using the FindByValue method on the items collection and then set the Selected property to true:

ddlMyList.Items.FindByValue("stringforselectedvalu e").Selected = true;

hth

"Steven" <ms******@berkovitz.org> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Hi there,

I am having a problem with an ASP.NET DropDown list - whenever I set the SelectedValue (or SelectedIndex) property, when the page displays, only
the
first item is ever selected. This is a databound dropdown, and I have
executed the DataBind() method prior to trying to set the
selectedvalue property. Both are being done in the Page_Load method, and only if

the page
is not posting back.

Any ideas would be appreciated.

-Steven



Nov 15 '05 #4

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

Similar topics

24
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
0
by: Ivan D. | last post by:
I am making a User Control in visual basic, it contains a Picture Box. To allow the image to change at design time I added a property. When changing a *normal* PictureBox Image at design time in...
2
by: Grzegorz ¦lusarek | last post by:
hello. I've code like this: var x =window.open('http://localhost/canvas.html','myokno') var w =x.width Permission denied to get property Window.width var w =x.innerWidth Permission denied to...
0
by: Merdaad | last post by:
Hi, In my dropdown I bind to a datasource. After that I try to do one of the following: 1. Add an Item to the dropdown using dd.Items.Add(newe ListItem("textstr")); 2. Change the text of an...
1
by: Kurt Schroeder | last post by:
I have a datagrid that includes a dropdown in an edit template. It creates ok, but i'm not sure how to set the selectedvalue based on the table in the dataset. given that the dataset DsSubTypes1...
1
by: xavier | last post by:
I found a good sample on the MSDN but if i change the property dropdownlist to dropdown I have a problem. When my cell has the focus, the next cell is automaticly selected.
1
by: Bruce A. Julseth | last post by:
Sorry. The other post got sent before I was complete. Does the ValueMember property in the ComboBox work like the DisplayMember property. For example, if I set the properties: ...
1
by: Fredo | last post by:
I'm getting the following error when I'm running my application (application name changed for the example): Unhandled Exception: System.TypeLoadException: Method get_ImageFile in type...
2
by: bimal0131 | last post by:
Hi, I m Binding a Listview,In edit Mode I M binding a Dropdown(Country) through other database and onselectIndexChange of this Dropdown i m binding three Dropdown bt Country is not in my table so i...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.