J
John Kotuby
Hi all,
I think this should be a very easy thing to do, but I am having difficulty
finding the documentation or maybe just my implementaion is wrong. I fill a
single-select listbox with US State names and Abbreviations.
Here is the code:
If StateTable.Rows.Count > 0 Then
Dim lstValue, lstText As String
lststate.Items.Clear()
For Each row As DataRow In StateTable.Rows
lstValue = row.Item("id").ToString
lstText = row.Item("name").ToString
Me.lststate.Items.Add(New ListItem(lstText, lstValue))
Next
End If
Dim i As Integer
i = lststate.Items.IndexOf(lststate.Items.FindByValue(state))
'Response.Write(CStr(i))
'Response.End()
Me.lststate.SelectedIndex = i
The contents of the variable "state" which I am using for the search is
"CT", a value that definitely exists in the StateTable.
The displayed text is the "name" field from the StateTable. I am assuming
that the value is the "id" because of the way I am populating the listbox.
Me.lststate.Items.Add(New ListItem(lstText, lstValue))
The listbox is definitely populating but the displayed text at the top is
Alaska (the first state in the table).
I am trying to set the Selected Index according to a known state
abbreviation which exists in the listbox. It is correct in the table.
But, my debugging code that displays the value i returned by
lststate.Items.IndexOf(lststate.Items.FindByValue(state))
is always -1.
There must be an easy way to do this, but for the moment I am stumped.
Thanks for any help...
I think this should be a very easy thing to do, but I am having difficulty
finding the documentation or maybe just my implementaion is wrong. I fill a
single-select listbox with US State names and Abbreviations.
Here is the code:
If StateTable.Rows.Count > 0 Then
Dim lstValue, lstText As String
lststate.Items.Clear()
For Each row As DataRow In StateTable.Rows
lstValue = row.Item("id").ToString
lstText = row.Item("name").ToString
Me.lststate.Items.Add(New ListItem(lstText, lstValue))
Next
End If
Dim i As Integer
i = lststate.Items.IndexOf(lststate.Items.FindByValue(state))
'Response.Write(CStr(i))
'Response.End()
Me.lststate.SelectedIndex = i
The contents of the variable "state" which I am using for the search is
"CT", a value that definitely exists in the StateTable.
The displayed text is the "name" field from the StateTable. I am assuming
that the value is the "id" because of the way I am populating the listbox.
Me.lststate.Items.Add(New ListItem(lstText, lstValue))
The listbox is definitely populating but the displayed text at the top is
Alaska (the first state in the table).
I am trying to set the Selected Index according to a known state
abbreviation which exists in the listbox. It is correct in the table.
But, my debugging code that displays the value i returned by
lststate.Items.IndexOf(lststate.Items.FindByValue(state))
is always -1.
There must be an easy way to do this, but for the moment I am stumped.
Thanks for any help...