By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,192 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,192 IT Pros & Developers. It's quick & easy.

Help: Using Multiple Checkboxes in a Checkboxlist to filter results in a gridview in ASP.NET 2.0

P: n/a
This seems like a simple task, but my 6 year old roots in classic ASP
must be causing me trouble with my current problem. I am looking to
provide a search for users in which they can select multiple categores
(check boxes) and view only the results in those categories in a
gridView control. My goal is to do so for movies, so an example would
be if the user checks comedy and childrens then they would only get
childrens comedies and the other "non children" comedies would be left
out of the list.

I can use the ControlParameter and link it to the CheckBoxList, but it
only responds to the first SelectedValue and not all of the Checked

I can generate the SQL statement that I need to execute based on the
check boxes on the Page_Load event after a post back. i.e. SELECT *
FROM movies WHERE Category Like '%comedy%' and Category Like
'%Children%'. I can't seem to force this SQL statement to run on the
SQLDataSource control and display in my GridView

Where am i going wrong? Here is the ASPX page code:

<form id="form1" runat="server">
<asp:CheckBoxList ID="CategoryList" runat="server"
CellPadding="8" CellSpacing="0"
<asp:ListItem>Martial Arts</asp:ListItem>
<asp:ListItem>Science Fiction</asp:ListItem>
<asp:ListItem>Gangster Film</asp:ListItem>
<asp:ListItem>Family </asp:ListItem>
<asp:ListItem>Historical </asp:ListItem>
<asp:Button ID="btnSearch" runat="server" Text="Search for
Movies" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" AllowSorting="True" PageSize="20" Font-Names="Arial"
Font-Size="Small" Font-Underline="False">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<asp:BoundField DataField="NUM" HeaderText="NUM"
<ItemStyle VerticalAlign="Top" />
<asp:HyperLinkField DataNavigateUrlFields="NUM"
DataTextField="ORIGINALTITLE" HeaderText="TITLE"
<ItemStyle VerticalAlign="Top" Wrap="False" />
<asp:TemplateField HeaderText="RATING"
<%# GetRatingImage(Eval("Rating")) %>
<asp:BoundField DataField="CATEGORY"
HeaderText="CATEGORY" SortExpression="CATEGORY">
<ItemStyle VerticalAlign="Top" />
<asp:BoundField DataField="YEAR" HeaderText="YEAR"
<ItemStyle VerticalAlign="Top" />
<asp:BoundField DataField="LENGTH" HeaderText="LENGTH"
<ItemStyle VerticalAlign="Top" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775"
<PagerSettings PageButtonCount="30" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:GillysplaceConnectionString %>"
SelectCommand="SELECT * FROM [movies] WHERE ([CATEGORY] LIKE '%' +
@CATEGORY + '%')">
<asp:ControlParameter ControlID="CategoryList"
Name="CATEGORY" PropertyName="SelectedValue"
Type="String" />
<br />
<br />
<asp:Label ID="theSQLStatement" runat="server"></asp:Label>

Dec 4 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.