Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:50:19+00:00 2026-06-07T11:50:19+00:00

I had data bind checkboxlist to a SQL Server, which display the items in

  • 0

I had data bind checkboxlist to a SQL Server, which display the items in the “Name” (using movie as an example: comedy, action, horror) column of my database . The checkboxlist acts as a filter so that when user checked on the checkboxes, the related movie would appear.

I had managed to databind the checkboxlist. The value of the checkboxes have value that are bind to the “CategoryId” of the database. But I have no idea on how to proceed further, which is to display datalist of movie poster(images) when the checkbox is checked.

For example, when I check the “Comedy” checkbox, the movies poster(datalist) that belong to that genre would appear.

Here is the code that I have done so far, default.aspx:

       <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DVDShopConnectionString %>" 
            SelectCommand="SELECT [ProductID], [Title], [Image1FileName] FROM [Product]"></asp:SqlDataSource>


        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DVDShopConnectionString %>" 
            SelectCommand="SELECT * FROM [Category]"></asp:SqlDataSource>
        <br />


        <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="CategoryID" 
            onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
        </asp:CheckBoxList>



<asp:datalist runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSource1" 
            RepeatColumns="4" ID="DataList1" >
    <ItemTemplate>


        <asp:Image ID="Image1" runat="server" 
         ImageUrl='<%# Eval("Image1FileName", "~/ProductImages/{0}") %>'  />
         <br /> 

        <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
        <br />


        <br />
<br />
    </ItemTemplate>
        </asp:datalist> 

Behind code:

private SqlDataReader getReader()
{
    //get connection string from web.config
    string strConnectionString = ConfigurationManager.ConnectionStrings["DVDShopConnectionString"].ConnectionString;
    SqlConnection myConnect = new SqlConnection(strConnectionString);

    string strCommandText = "SELECT CategoryID, Name  from Category";

    SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
    myConnect.Open();

     //DataList1.DataSource = reader; 
     DataList1.DataBind();
    // CommandBehavior.CloseConnection will automatically close connection
    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    return reader;
}




protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{


    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
        if (CheckBoxList1.Items[i].Selected == true)
        {
            //items should be filter here.. 

        }
    }
} 

Any suggestions or ideas are greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:50:20+00:00Added an answer on June 7, 2026 at 11:50 am

    I’ll suggest an answer that I hadn’t tested, so please give me any feedback.
    Let’s see:

    1. Get rid of that getReader() method, you don’t need all data as long as you are using a SqlDataSource. Simply do this at Page_Load

      if(!this.IsPostBack)
      {
      this.CheckBoxList1.DataBind();
      }

    2. At CheckBoxList1_SelectedIndexChanged, get all checked values and concatenate them on a query for movies, like SELECT [ProductID], [Title], [Image1FileName] FROM [Product] WHERE CategoryId IN ( put the IDs here )

    3. Set this query as the command for SqlDataSource1

    4. Call DataList1.DataBind();

    Please, test it and give me any feedback.

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had grid view which bind sql data source and added field to update
I had Repeater which bind method this method retrieve data from data base by
Note: I had another similar question about how to GZIP data using Ruby's zlib
I had to convert some code (which deals with building a VBO of data
I've had to create a custom model binder to bind data for a complex
I am using jsTree to display a tree structure of hierarchical data within my
When I had a Typed DataTable with information retrieved from a SQL Server with
I ran into a bind whereby I had to sort the data read from
I want to bind Data from DB to DropDownList ,i had tried the following
I am retrieving the following sql statement from a table and then using bind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.