J
John Wright
I have two listboxes on my form that are populated from a datatable. I have
the selectionmode set to multiselect and the tables are populated correctly
with the correct values and text properties. The problem I have is
extracting which values are selected in the list. I have the following code
that iterates over the list. If the item is selected, I create a parameter,
call the stored proc in SQL server to update and move on. No problem. The
problem I get is that no listitem in the listbox indicates it is selected,
even though I have selected multiple items (or even single items) I can't
get anything to show as selected. I have included the web page control
code, the binding code and the code to iterate the control. Can anyone see
what I am missing.
John.
List box page code
<asp:ListBox ID="lbConditions" runat="server" Height="72px"
SelectionMode="Multiple"
Width="224px"></asp:ListBox><br />
Code that iterates the list box
For Each lstCond As ListItem In lbConditions.Items
If lstCond.Selected Then
objParam.CreateParameter("EventID", intTripID, DbType.Int32,
ParameterDirection.Input)
objParam.CreateParameter("ConditionID", lstCond.Value, DbType.Int32,
ParameterDirection.Input)
objDAL.ExecuteNonQuery("AddEventCondition", objParam)
objParam.Clear()
End If
Next
Code that binds the control
dtConditions = objDAL.ExecuteDataTable("GetEventConditions", objParam)
lbConditions.DataSource = dtConditions
lbConditions.DataTextField = "ConditionName"
lbConditions.DataValueField = "EventConditionID"
lbConditions.SelectionMode = ListSelectionMode.Multiple
lbConditions.DataBind()
the selectionmode set to multiselect and the tables are populated correctly
with the correct values and text properties. The problem I have is
extracting which values are selected in the list. I have the following code
that iterates over the list. If the item is selected, I create a parameter,
call the stored proc in SQL server to update and move on. No problem. The
problem I get is that no listitem in the listbox indicates it is selected,
even though I have selected multiple items (or even single items) I can't
get anything to show as selected. I have included the web page control
code, the binding code and the code to iterate the control. Can anyone see
what I am missing.
John.
List box page code
<asp:ListBox ID="lbConditions" runat="server" Height="72px"
SelectionMode="Multiple"
Width="224px"></asp:ListBox><br />
Code that iterates the list box
For Each lstCond As ListItem In lbConditions.Items
If lstCond.Selected Then
objParam.CreateParameter("EventID", intTripID, DbType.Int32,
ParameterDirection.Input)
objParam.CreateParameter("ConditionID", lstCond.Value, DbType.Int32,
ParameterDirection.Input)
objDAL.ExecuteNonQuery("AddEventCondition", objParam)
objParam.Clear()
End If
Next
Code that binds the control
dtConditions = objDAL.ExecuteDataTable("GetEventConditions", objParam)
lbConditions.DataSource = dtConditions
lbConditions.DataTextField = "ConditionName"
lbConditions.DataValueField = "EventConditionID"
lbConditions.SelectionMode = ListSelectionMode.Multiple
lbConditions.DataBind()