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

Drop down not selecting properly

Hi

Another problem...

My drop down is always defaulting to selecting the first item in the
drop down, even though I've got code specifically to change it to a
different item:

Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT appId, appName FROM application WHERE segmentID
= " + segmentID.ToString(), connection)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet)
ApplicationDropDown.DataValueField = "appId"
ApplicationDropDown.DataTextField = "appName"
ApplicationDropDown.DataSource = dataSet
ApplicationDropDown.DataBind()

ApplicationDropDown.Items.FindByValue(ApplicationI d.ToString()).Selected
= True

Why is the item not being selected? I've checked that the
ApplicationId is correct and it is. I'm really scratching my head on
this one.

Mark
Jun 27 '08 #1
3 1221
<ma**********@gmail.comwrote in message
news:52**********************************@z72g2000 hsb.googlegroups.com...
My drop down is always defaulting to selecting the first item in the
drop down, even though I've got code specifically to change it to a
different item:

Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT appId, appName FROM application WHERE segmentID
= " + segmentID.ToString(), connection)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet)
ApplicationDropDown.DataValueField = "appId"
ApplicationDropDown.DataTextField = "appName"
ApplicationDropDown.DataSource = dataSet
ApplicationDropDown.DataBind()

ApplicationDropDown.Items.FindByValue(ApplicationI d.ToString()).Selected
= True

Why is the item not being selected? I've checked that the
ApplicationId is correct and it is. I'm really scratching my head on
this one.
There doesn't appear to be anything wrong with your code, so...

1) When you stepped through this in debug mode, what were the values of
ApplicationDropDown.SelectedValue *and* ApplicationDropDown.SelectedIndex
immediately before and after the FindByValue line...?

2) Might there be something later in the page lifecycle which is resetting
the DropDown, or maybe even client-side JavaScript...?

3) Case-sensitivity...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
If you're populating the ddl in the Page_Load event, be sure to surround it
with an if/then/postback block:
if not page.isPostback then
' do ddl population
end if

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
<ma**********@gmail.comwrote in message
news:52**********************************@z72g2000 hsb.googlegroups.com...
Hi

Another problem...

My drop down is always defaulting to selecting the first item in the
drop down, even though I've got code specifically to change it to a
different item:

Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT appId, appName FROM application WHERE segmentID
= " + segmentID.ToString(), connection)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet)
ApplicationDropDown.DataValueField = "appId"
ApplicationDropDown.DataTextField = "appName"
ApplicationDropDown.DataSource = dataSet
ApplicationDropDown.DataBind()

ApplicationDropDown.Items.FindByValue(ApplicationI d.ToString()).Selected
= True

Why is the item not being selected? I've checked that the
ApplicationId is correct and it is. I'm really scratching my head on
this one.

Mark

Jun 27 '08 #3
On 20 May, 14:57, "David Wier" <d...@dw.comwrote:
If you're populating the ddl in the Page_Load event, be sure to surround it
with an if/then/postback block:
if not page.isPostback then
' do ddl population
end if

David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert.doc/.rtf/.txt to HTML with no
bloated markup

<mark.norg...@gmail.comwrote in message

news:52**********************************@z72g2000 hsb.googlegroups.com...
Hi
Another problem...
My drop down is always defaulting to selecting the first item in the
drop down, even though I've got code specifically to change it to a
different item:
* * * * * * * *Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT appId, appName FROM application WHERE segmentID
= " + segmentID.ToString(), connection)
* * * * * * * *Dim dataSet As DataSet = New DataSet()
* * * * * * * *adapter.Fill(dataSet)
* * * * * * * *ApplicationDropDown.DataValueField = "appId"
* * * * * * * *ApplicationDropDown.DataTextField = "appName"
* * * * * * * *ApplicationDropDown.DataSource = dataSet
* * * * * * * *ApplicationDropDown.DataBind()
ApplicationDropDown.Items.FindByValue(ApplicationI d.ToString()).Selected
= True
Why is the item not being selected? I've checked that the
ApplicationId is correct and it is. I'm really scratching my head on
this one.
Mark- Hide quoted text -

- Show quoted text -
I've completely rewritten this section of code now and it works fine.
Thanks for your replies.

Mark
Jun 27 '08 #4

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

Similar topics

1
by: Smriti Dev | last post by:
Hi, I have a drop down menu with a listing of communities and I use it to select a community, selecting a letter ie. "T" , I get bumped to the "T" section to choose communities that start with...
10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
0
by: Mythran | last post by:
I wrote an editor for a web control that allows it to list all controls on a page in a drop down box in the property grid. In the EditValue method, I have the following (not all the code, but most...
3
by: KatMagic | last post by:
How do you force a drop down list to default to a particular item based on its value? I have a drop down list with options Yes, No, Maybe, All, and I would like it to default to "All" This is...
2
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I have a problem and hope I can get the better solution from here. I have a form written in HTML and I need to write that in perl so the main problem I am facing is that I need to...
3
by: amcoldspy | last post by:
Hi, am trying to create dynamic drop down boxes.. there are 3 drop down boxes. The second drop down box elements are to be update based on the selection made in the first drop down box...
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: 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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.