473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
items.

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">
<div>
<asp:CheckBoxList ID="CategoryList" runat="server"
CellPadding="8" CellSpacing="0"
RepeatColumns="5">
<asp:ListItem>Action</asp:ListItem>
<asp:ListItem>Comedy</asp:ListItem>
<asp:ListItem>Adventure</asp:ListItem>
<asp:ListItem>Thriller</asp:ListItem>
<asp:ListItem>War</asp:ListItem>
<asp:ListItem>Drama</asp:ListItem>
<asp:ListItem>Fantasy</asp:ListItem>
<asp:ListItem>Martial Arts</asp:ListItem>
<asp:ListItem>Science Fiction</asp:ListItem>
<asp:ListItem>Spy</asp:ListItem>
<asp:ListItem>Disaster</asp:ListItem>
<asp:ListItem>Crime</asp:ListItem>
<asp:ListItem>Children</asp:ListItem>
<asp:ListItem>Horror</asp:ListItem>
<asp:ListItem>Animation</asp:ListItem>
<asp:ListItem>Biography</asp:ListItem>
<asp:ListItem>Holiday</asp:ListItem>
<asp:ListItem>Musical</asp:ListItem>
<asp:ListItem>Gangster Film</asp:ListItem>
<asp:ListItem>Family </asp:ListItem>
<asp:ListItem>Sports</asp:ListItem>
<asp:ListItem>Historical </asp:ListItem>
<asp:ListItem>Mystery</asp:ListItem>
<asp:ListItem>Romance</asp:ListItem>
<asp:ListItem>Western</asp:ListItem>
</asp:CheckBoxList>&nbsp;</div>
<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" />
<Columns>
<asp:BoundField DataField="NUM" HeaderText="NUM"
SortExpression="NUM">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="NUM"
DataNavigateUrlFormatString="details.aspx?Num={0}"
DataTextField="ORIGINALTITLE" HeaderText="TITLE"
SortExpression="ORIGINALTITLE">
<ItemStyle VerticalAlign="Top" Wrap="False" />
</asp:HyperLinkField>
<asp:TemplateField HeaderText="RATING"
SortExpression="Rating">
<ItemTemplate>
<%# GetRatingImage(Eval("Rating")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CATEGORY"
HeaderText="CATEGORY" SortExpression="CATEGORY">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="YEAR" HeaderText="YEAR"
SortExpression="YEAR">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="LENGTH" HeaderText="LENGTH"
SortExpression="LENGTH">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
</Columns>
<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:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:GillysplaceConnectionString %>"
SelectCommand="SELECT * FROM [movies] WHERE ([CATEGORY] LIKE '%' +
@CATEGORY + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="CategoryList"
Name="CATEGORY" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="theSQLStatement" runat="server"></asp:Label>
</form>

Dec 4 '06 #1
0 2729

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
2
by: John Hoge | last post by:
I'm looking for that elusive .net time saving magic. I have an application that presents a list of items which the user can select from. A CheckBoxList works great for that, but I want to query...
0
by: Faybert | last post by:
Hello, and Thanks in advance for any light you might shed on my troubles. I'm trying to setup a series of checkboxes, or a checkboxlist to control the results that are shown on a gridview...
1
by: SalamElias | last post by:
When I add checkboxes dynamically, I can set several attributes(id, eventhandlers specific to checkboxes....) in code. I decided to use the checkboxlist to generate several checkboxes dynamically...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: mutt1170 | last post by:
I have a checkbox list nested inside a gridview. The gridview pulls its data from an objectdatasource and lists countries. The nested checkbox list is databound to another object datasource and...
0
by: Ned Balzer | last post by:
Hi, Can anyone point me in the direction of a solution for validating multiple checkboxes in an asp.net 2.0 page? 1) This is not a checkboxlist, it is a number of separate checkboxes 2) I do...
3
by: santoshjsh | last post by:
hello everyone, i have a gridview in which i have multiple checkboxes in a single column. means for every row in the gridview i have four checkboxes in one column e.g Add, Delete, Print,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.