Answered by:
How do I use multiple selected values from checkbox to modify datasource for gridview

Question
-
Hi
I have a checkbox that I have bound to a SQL data source to populate.
I have also a Gridview which is also bound to another SQL datasource but uses the checkbox selected values to modify the WHERE clause.
However the Gridview seem to allow only the first selected value from the checkbox to modify the WHERE clause.
Can someone tell me how to get the multiple values as part of the WHERE clause?
The following is the gridview definition.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="AssetID" HeaderText="AssetID"/>
<asp:BoundField DataField="ClassID" HeaderText="ClassID"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:AssetMgtConnectionString %>"
SelectCommand="SELECT AssetID, Class.ClassID FROM Assets WHERE ((Class.ClassID = @id))">
<SelectParameters>
<asp:ControlParameter ControlID="CheckBoxList1" Name="id" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>Worst case I can code it by looping through the Checkbox Control and modifying the SelectCommand but I am hoping it would be easier by tweaking the SQLDataSource2 Control.
Thanks.
Regards Andre Thompson- Moved by CoolDadTx Friday, October 28, 2011 9:26 PM Not IDE related (From:Visual C# IDE)
- Moved by Leo Liu - MSFT Thursday, November 3, 2011 3:17 AM Off-Topic (From:Visual C# General)
Friday, October 28, 2011 9:00 PM
Answers
-
- Proposed as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:37 AM
Saturday, October 29, 2011 1:19 AM -
Hi Andre,
Please follow Link.fr 's suggestion to post in the dedicated forum for better support.
Thanks for your understanding.
Have a nice day,
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
Monday, October 31, 2011 4:31 AM
All replies
-
- Proposed as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:37 AM
Saturday, October 29, 2011 1:19 AM -
Hi Andre,
Please follow Link.fr 's suggestion to post in the dedicated forum for better support.
Thanks for your understanding.
Have a nice day,
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, November 3, 2011 5:36 AM
Monday, October 31, 2011 4:31 AM -
Thanks.
Regards Andre ThompsonMonday, October 31, 2011 5:49 PM