Hello,
I am pretty new to ASP.NET, I hope someone can help me out. I am having problem with list box
I can't seem to get any item selected when the list coming from database, but if I manually add listitem, I could select an item. I dont understand where I get wrong
here's my HTML:
<asp:Listbox id="txtAllLocationID" runat="server" Width="125px" SelectionMode="Multiple"
DataValueField="locationID" DataTextField="location" rows="8" EnableViewState="true" Enabled="true">
</asp:Listbox>
and I have a button to add location from this list box, here's my codebehind:
binding listbox to the datasource:
strSQL = "EXEC sp_VM_getVMAlllocation '" & strUsername & "', '" & intVMID & "'"
objCommand = New SqlClient.SqlCommand(strSQL, objConnection)
objReader = objCommand.ExecuteReader()
txtAllLocationID.DataSource = objReader
txtAllLocationID.DataTextField = "location"
txtAllLocationID.DataValueField = "locationID"
txtAllLocationID.DataBind()
objReader.Close()
and the button click:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim LocationItem As ListItem
For Each LocationItem In txtAllLocationID.Items
If LocationItem.Selected Then
strSQL = "EXEC sp_VM_addCurrentLocation '" & strUsername & "', '" & intVMID & "', '" & LocationItem.Value & "'"
objCommand = New SqlClient.SqlCommand(strSQL, objConnection)
objCommand.ExecuteNonQuery()
End If
Next
End Sub
I have been on to this all morning and I am stuck, if someone can help me out it would be great. Thanks in advanced!!!!