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**************@TK2MSFTNGP09.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.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
The line below doesn't do anything new. It is constantly setting the
selected item to be selected again.
StateCode.SelectedItem.Selected = 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.microsoft.com> wrote in
message news:CB**********************************@microsof t.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(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Get_States",
myConnection)
Dim Statetypes As SqlDataReader
myConnection.Open()
Statetypes = myCommand.ExecuteReader
StateCode.DataSource = Statetypes
StateCode.DataTextField = "State"
StateCode.DataValueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataBind()
myConnection.Close()
Dim i As Integer
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
end if