Drop down not selecting properly

  • Thread starter Thread starter mark.norgate
  • Start date Start date
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
 
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
 
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
 
Back
Top