How do I use multiple selected values from checkbox to modify datasource for gridview RRS feed

  • 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">
             <asp:BoundField DataField="AssetID" HeaderText="AssetID"/>
                    <asp:BoundField DataField="ClassID" HeaderText="ClassID"/>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
     ConnectionString="<%$ ConnectionStrings:AssetMgtConnectionString %>"
            SelectCommand="SELECT AssetID, Class.ClassID FROM Assets WHERE ((Class.ClassID = @id))">
             <asp:ControlParameter ControlID="CheckBoxList1" Name="id" PropertyName="SelectedValue" />

    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.



    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


All replies