Home All Groups Group Topic Archive Search About

Getting multi values from a list box

Author
27 Sep 2006 9:18 PM
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()

Author
28 Sep 2006 1:23 AM
Gaurav Vaish (www.EduJiniOnline.com)
> If lstCond.Selected Then
>
> objParam.CreateParameter("EventID", intTripID, DbType.Int32,
> ParameterDirection.Input)

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.


Author
28 Sep 2006 12:30 PM
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)"
<gaurav.vaish.nospam@nospam.gmail.com> wrote in message
Show quoteHide quote
news:u15JKzp4GHA.1196@TK2MSFTNGP02.phx.gbl...
>> If lstCond.Selected Then
>>
>> objParam.CreateParameter("EventID", intTripID, DbType.Int32,
>> ParameterDirection.Input)
>
> 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
> -------------------
>
>
Author
28 Sep 2006 1:44 PM
Gaurav Vaish (www.EduJiniOnline.com)
> correctly, the problem is none of the items in the listbox are recognized
> as selected, it has nothing to do with the database.

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.