Data Binding: GridView & CheckBoxList & SQL

R

rob

Here is my scenario:

One of my aspx pages has a CheckBoxList (Item1, Item2) and a GridView.
Then I have a database that has the columns Item1 and Item2 (among
others) with the data type bit. What I am trying to do is to only show
the data sets chosen by the user. So for example if the user checks
Item1 in the CheckBoxList then only the datasets that have Item1 set to
True should be listed in the GridView. Here is what I tried:

Checkboxlist
------------
<asp:CheckBoxList OnSelectedIndexChanged="ItemsIndexChanged
ID="CheckBoxListItems" RepeatColumns="2"
RepeatDirection="Vertical"
RepeatLayout=Table TextAlign="Right" Runat="server" >
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
</asp:CheckBoxList>

GridView
--------
<asp:GridView ID="GridView1" Runat="server"
DataSourceID="SqlDataSourceItems"
AutoGenerateColumns="False" AllowSorting="True"
AllowPaging="True">
<Columns>
<asp:BoundField HeaderText="Item1" DataField="Item1"
SortExpression="Item1">
</asp:BoundField>
<asp:BoundField HeaderText="Item2" DataField="Item2"
SortExpression="Item2">
</asp:BoundField>
</Columns>
</asp:GridView>

SqlDataSource
-------------
<asp:SqlDataSource ID="SqlDataSourceTssdSecFilling" Runat="server"
SelectCommand="SELECT * FROM [MyTable]
WHERE (([Item1] = @Item1) AND ([Item1] = @Item2))"
ConnectionString="<%$ ConnectionStrings:AppConnectionItems %>"
OnSelecting="SqlDataSourceItems_Selecting">
<SelectParameters>
<asp:ControlParameter Name="Item1"
ControlID="CheckBoxListItems" Type="Boolean"
PropertyName="??????">
</asp:ControlParameter>
<asp:ControlParameter Name="Item2"
ControlID="CheckBoxListItems" Type="Boolean"
PropertyName="??????">
</asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>

I just can't get this to work no matter what I set for the two
controlParameters in the SqlDataSource. It works just fine for a
TextBox. Any help is appreciated.

Regards,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top