I am trying to select a value from the list control. If the user select "ALL" I would like to pass the value to my sql statement. if the user select more than one value, I would like to separte the values in comma and pass to the query. I have the code below and my problem is it is not passing "ALL" when the user select it from the list control to the query. please help
Code:
Sub WriteState()
Dim VendorState As String = "select distinct state optVal, (state ||' : '||func_get_state_desc(state)) optTxt from refvendoraddress where state is not null "
VendorState = VendorState & " order by state "
Dim dapVendorState As OracleDataAdapter = New OracleDataAdapter(VendorState, GetConnectionString)
Dim dsVendorState As DataSet = New DataSet
dapVendorState.Fill(dsVendorState, "Vendorcity")
lstState.DataSource = dsVendorState
lstState.DataTextField = "optTxt"
lstState.DataValueField = "optVal"
lstState.DataBind()
lstState.Width = "300"
lstState.Items.Insert(0, New System.Web.UI.WebControls.ListItem("ALL", 0))
lstState.Items.FindByValue(0).Selected = True
End Sub
For Each liCntState In lstState.Items
If liCntState.Selected Then
strStates = liCntState.Value
Else
strStates = strStates & "'" & liCntState.Value & "'" & ","
End If
Next
If (strStates.Length > 0) Then 'And lstcontrcvd.SelectedIndex <> 0) Then
If strStates = "0" Then
strStates = Left(strStates, strStates.Length - 1)
Else
strStates = Left(strStates, strStates.Length - 1)
strStates = "(" & strStates & ")"
End If
End If