By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,403 Members | 1,344 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,403 IT Pros & Developers. It's quick & easy.

Drop down not selecting properly

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
<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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.