Hi,

What is the best way to control data displayed by a GridView when using a listbox that allows you to make multiple selections. I'm currently using a Select Parameter to control the data displayed (using the WHERE clause of the SQL Select Query), though the FilterParameter would make more sense (if I could figure out how to use it). The select parameter is set to the SelectedValue property of the ListBox, but when multiple selections are made, only one SelectedValue is available through the property (the one with the lowest index, I think), thus showing only on of the selected groups in the GridView.

This is the portion of the page that is important:

<asp:ListBox ID="lstTypes" runat="server" Rows="5" SelectionMode="Multiple" DataSourceID="SqlItemTypes" DataTextField="item_type_name" DataValueField="item_type_id"></asp:ListBox> 
<asp:SqlDataSource ID="SqlItemTypes" runat="server" ConnectionString="<%$ ConnectionStrings:sysObjDBConnectionString %>"
SelectCommand="SELECT [item_type_name], [item_type_id] FROM [ITEM_TYPE_REF]"></asp:SqlDataSource>
<asp:GridView ID="grdItemInventory" runat="server" AutoGenerateColumns="False" DataKeyNames="item_id"
DataSourceID="SqlItemInventory">
<Columns>
<asp:BoundField DataField="item_id" HeaderText="item_id" InsertVisible="False" ReadOnly="True"
SortExpression="item_id" />
<asp:BoundField DataField="CheckedOut" HeaderText="CheckedOut" ReadOnly="True" SortExpression="CheckedOut" />
<asp:BoundField DataField="item_type_name" HeaderText="item_type_name" SortExpression="item_type_name" />
<asp:BoundField DataField="item_name" HeaderText="item_name" SortExpression="item_name" />
<asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" SortExpression="Status" />
<asp:BoundField DataField="Responsible" HeaderText="Responsible" ReadOnly="True"
SortExpression="Responsible" />
<asp:BoundField DataField="item_inv_no" HeaderText="item_inv_no" SortExpression="item_inv_no" />
<asp:BoundField DataField="CheckedOutBy" HeaderText="CheckedOutBy" ReadOnly="True"
SortExpression="CheckedOutBy" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlItemInventory" runat="server" ConnectionString="<%$ ConnectionStrings:sysObjDBConnectionString %>"
SelectCommand="select i.item_id /*1*/, (CASE WHEN EXISTS(SELECT * FROM ITEM_CHECKOUT AS c WHERE c.item_id = i.item_id AND c.item_checkin_dt IS NULL) THEN 1 ELSE 0 END) AS CheckedOut /*2*/, tr.item_type_name /*3*/, i.item_name /*4*/, (SELECT sr.item_status_ref_name FROM ITEM_STATUS_REF AS sr WHERE sr.item_status_ref_id = (SELECT s.item_status_ref_id FROM ITEM_STATUS AS s WHERE s.item_status_dt = (SELECT MAX(item_status_dt) FROM ITEM_STATUS WHERE item_id = i.item_id) AND s.item_id = i.item_id)) AS Status /*5*/, iu.lastName + ', ' + iu.firstName AS Responsible /*6*/, i.item_inv_no /*7*/, (SELECT cu.lastName + ', ' + cu.firstName FROM userAccounts AS cu WHERE cu.userUID = (SELECT c.userUID FROM ITEM_CHECKOUT AS c WHERE c.item_id = i.item_id AND c.item_checkin_dt IS NULL)) AS CheckedOutBy /*8*/ FROM ITEM AS i LEFT OUTER JOIN ITEM_TYPE_REF AS tr ON tr.item_type_id = i.item_type_id LEFT OUTER JOIN userAccounts AS iu ON iu.userUID = i.userUID WHERE i.item_enable_checkout = 1 AND i.item_type_id = @item_type_id">
<FilterParameters>
<asp:ControlParameter ControlID="lstTypes" Name="item_type_id" PropertyName="SelectedValue" />
</FilterParameters>
<SelectParameters>
<asp:ControlParameter ControlID="lstTypes" Name="item_type_id" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

The selectedvalue will return only the listitem that has focus.
Loop through the listbox items to determine which are selected.

For Each item As ListItem In ListBox1.Items
            If item.Selected = True Then
                'do something
            End If
Next

Yeah, I got that pretty easily. I just couldn't think of out to select record for all of the selected values each time the grid was databound. I ended up using a similar loop structure and then added " OR item_type_id = X " on each iteration in which the item was selected. Thanks anyway

This question has already been answered. Start a new discussion instead.