Hi,
I forgot to mention after you set the Selected property to True then put in
an Exit For to exit you from the loop:
If Statechk = customerDetails .State Then
StateCode.Items (i).Selected = True
Exit For 'Get out before it finds another one! Just kidding....
End If
Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"Ken Dopierala Jr." <kd*********@wi .rr.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
Your problem is in this code:
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = True
End If
Next
The line below doesn't do anything new. It is constantly setting the
selected item to be selected again.
StateCode.Selec tedItem.Selecte d = True
You would want to do something like this in its place:
StateCode.Items (i).Selected = True
Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"Stanley J Mroczek" <St************ *@discussions.m icrosoft.com> wrote in
message news:CB******** *************** ***********@mic rosoft.com... I have tried this with no luck. What i want is to show the selected item
on the first post. the selected item is NY but the first in the list shows
as selected.
If Page.IsPostBack = False Then
Dim myConnection As SqlConnection = New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Get _States",
myConnection)
Dim Statetypes As SqlDataReader
myConnection.Op en()
Statetypes = myCommand.Execu teReader
StateCode.DataS ource = Statetypes
StateCode.DataT extField = "State"
StateCode.DataV alueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataB ind()
myConnection.Cl ose()
Dim i As Integer
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = True
End If
Next
end if