all groups > asp.net webcontrols > september 2006 >
You're in the

asp.net webcontrols

group:

Getting multi values from a list box


Getting multi values from a list box John Wright
9/27/2006 3:18:57 PM
asp.net webcontrols: 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()

Re: Getting multi values from a list box Gaurav Vaish (www.EduJiniOnline.com)
9/28/2006 12:00:00 AM
[quoted text, click to view]

Instead of directly pushing it to parameters, first try to simply print it
on the browser (either in a Label or otherewise)...
Check if the problem is with getting the values or with the DB-code.


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------

Re: Getting multi values from a list box John Wright
9/28/2006 6:30:10 AM
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)"
[quoted text, click to view]

Re: Getting multi values from a list box Gaurav Vaish (www.EduJiniOnline.com)
9/28/2006 7:14:50 PM
[quoted text, click to view]

Have you tried checking the raw-request that is sent to sever on postback?

Request.InputStream ... read all contents into a file and see if the data is
being currently sent to the server.


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------

AddThis Social Bookmark Button