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

  • Home
  • SEARCH
  • 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 8160743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:20:42+00:00 2026-06-06T18:20:42+00:00

Basically I want to implement a filtering option for a Grid view and I

  • 0

Basically I want to implement a filtering option for a Grid view and I have a dropdown list containing the column names and a checkboxlist containing the available filtering values for that column. Every time I select a different column, I have to load the filtering values for that column into the checkbox list.
The problem I have is that when I change the column in the dropdown list, the event for the checklist is fired and the application crashes.

My controls are defined like this:

<div class="LeftAligned">  
     <asp:Label ID="FilterLabel" runat="server" Text="Filter by:" />  
     <asp:DropDownList runat="server" ID="FilterReviewsDropDownList" AutoPostBack="true" OnSelectedIndexChanged="FilterReviewsDropDownList_SelectedIndexChanged" />  
     <asp:ImageButton ID="FilterReviewsButton" runat="server" ImageUrl="~/images/filter.png" AlternateText="VALUE" CssClass="filter_button" OnClick="FilterReviewsButton_Click" />  
     <div onmouseout="javascript:bMouseOver=false;" onmouseover="javascript:bMouseOver=true;" class="filter_div">  
           <asp:CheckBoxList AutoPostBack="true" ID="FilterReviewsCheckBoxList" ClientIDMode="Static" runat="server" CssClass="filter_checklist collapsed"   
            OnSelectedIndexChanged="FilterReviewsCheckBoxList_Selected">  
           </asp:CheckBoxList>  
     </div>  
     <%--asp:Button runat="server" ID="ApplyFilterButton" Text="Apply Filter" OnClick="ApplyFilterButton_Click"/>  
     <asp:Button runat="server" ID="ClearFilterButton" Text="Clear Filter" OnClick="ClearFilterButton_Click"/--%>  
</div>

In the CodeBehind file I have the following code:

protected void FilterReviewsButton_Click(object sender, EventArgs e)
{
    FilterReviewsCheckBoxList.CssClass = "filter_checklist";
}

protected void FilterReviewsDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    LoadFilterCheckboxes(FilterReviewsDropDownList.SelectedIndex);
}

private void LoadFilterCheckboxes(int iColumn)
{
    SortedSet<string> oItems = new SortedSet<string>();

    for (int i = 0; i < ReviewsGridView.Rows.Count; i++)
    {
        IEnumerable<Label> oLabels = ReviewsGridView.Rows[i].Cells[iColumn].Controls.OfType<Label>();
        string sValue = "";
        if (oLabels != null && oLabels.Count() > 0)
        {
            sValue = oLabels.First().Text;
        }
        else
        {
            sValue = ReviewsGridView.Rows[i].Cells[iColumn].Text;
        }
        if (!oItems.Contains(sValue))
            oItems.Add(sValue);
    }

    FilterReviewsCheckBoxList.Items.Clear();
    FilterReviewsCheckBoxList.Items.Add("All");
    FilterReviewsCheckBoxList.Items[0].Selected = true;
    foreach (string sItem in oItems)
    {
        FilterReviewsCheckBoxList.Items.Add(sItem);
        FilterReviewsCheckBoxList.Items[FilterReviewsCheckBoxList.Items.Count - 1].Selected = true;
    }
}

protected void FilterReviewsCheckBoxList_Selected(object sender, EventArgs e)
{
    string sResult = Request.Form["__EVENTTARGET"];
    if (string.IsNullOrEmpty(sResult))
    {
        FilterReviewsCheckBoxList.Items[0].Selected = true; //weird bug fix...
        return;
    }

    string[] sCheckedBox = sResult.Split('$');
    //get the index of the item that was checked/unchecked
     int i = int.Parse(sCheckedBox[sCheckedBox.Length - 1].Split('_')[1]);
     if (i == 0)
     {
         if (FilterReviewsCheckBoxList.Items[i].Selected == true)
         {
             for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++)
                 FilterReviewsCheckBoxList.Items[j].Selected = true;
         }
         else
         {
            for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++)
                FilterReviewsCheckBoxList.Items[j].Selected = false;
         }
     }
     else
     {
        if (FilterReviewsCheckBoxList.Items[i].Selected == false)
        {
            FilterReviewsCheckBoxList.Items[0].Selected = false;
        }
        else
        {
            //if (oFirstTable != null)
            //{
            //    oTable = oFirstTable;
            //    oView = oTable.DefaultView;
            //}
            bool bAllChecked = true;
            for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++)
            {
                 if (FilterReviewsCheckBoxList.Items[j].Selected == false)
                 {
                     bAllChecked = false;
                     break;
                 }
            }
            if (bAllChecked)
                 FilterReviewsCheckBoxList.Items[0].Selected = true;
        }
    }
}

Any idea of why FilterReviewsCheckBoxList_Selected is called (with the dropdownlist as the sender argument) when changing the dropdown list?

  • 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-06T18:20:44+00:00Added an answer on June 6, 2026 at 6:20 pm

    For anyone who may encounter the same problem, the fix is to avoid static binding of the grid view to entity data source. Instead, bind the grid dynamically in the page load event.

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

Sidebar

Related Questions

I basically want to implement a Label and have it constantly showing information to
Basically I want to implement a simple Rails extension to define the seriousness of
I want to implement a version of Benford's law ( http://en.wikipedia.org/wiki/Benford%27s_law ) that basically
I have a large multidimensional array and I basically want to drop the first
Basically I want to implement something similar to the the cell-coloring which is defined
I want to implement my own tweet compressor . Basically this does the following.
I basically want to implement something where you can type in any URI (
We want to implement a overload mechanism on our axis Web Service. Basically we
I want to implement a preference screen. So I followed basically the example from
I want to implement an SSL proxy in Java. I basically open two sockets

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.