Drop down not selecting properly

M

mark.norgate

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(ApplicationId.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
 
D

David Wier

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
 
M

mark.norgate

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












- Show quoted text -

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

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top