Getting multi values from a list box

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()
 
J

John Wright

That makes no sense whatsoever. As I explained, the listboxes are populated
correctly, the problem is none of the items in the listbox are recognized as
selected, it has nothing to do with the database.

John
"Gaurav Vaish (www.EduJiniOnline.com)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top