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 7841557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:33+00:00 2026-06-02T16:07:33+00:00

I have 5 check box on my page and a Grid view with Template

  • 0

I have 5 check box on my page and a Grid view with Template Field, I am not using any bond field on page load I am binding the grid with all data of a table, I want to filter the data based on the check box check.

suppose: I have check box like A B C D. All check box are out side of Grid view. When user checked the check box A, then in Grid view, check box A related data should show, like wise for B C and D.

how do that?, Some one please give some example code and bit logic.

It would be great if I’ll be able to filter the gridview without any postback.

Grid:

 <asp:GridView ID="GridView1" runat="server" 
                AutoGenerateColumns="False" CellPadding="3">
      <Columns>
          <asp:TemplateField HeaderText="ID" SortExpression="ID">
            <ItemTemplate>
              <asp:Label ID="lblId" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
           </ItemTemplate>                           
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Discription" SortExpression="Discription">
            <ItemTemplate>
              <asp:Label ID="lblDiscription" runat="server" Text='<%#Eval("Discription") %>'></asp:Label>
            </ItemTemplate>                        
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Address" SortExpression="Address">
            <ItemTemplate>
             <asp:Label ID="lblAddress" runat="server" Text='<%#Eval("Address") %>'></asp:Label>
            </ItemTemplate>
         </asp:TemplateField>
     </Columns>
 </asp:GridView>

Binding the Grid:

TestPageDao page1Dao = new TestPageDao ();

if (!IsPostBack)
{
  IList<TestDAO> TestDAO = page1Dao.GetAlldata();
  GridView1.DataSource = TestDAO;
  GridView1.DataBind();
}

I tried Filter gridview or http://forums.asp.net/p/1034014/2904713.aspx

  • 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-02T16:07:35+00:00Added an answer on June 2, 2026 at 4:07 pm

    If you want to avoid postback, uses jQuery like here:
    http://jquerybyexample.blogspot.com/2012/04/how-to-filter-gridview-records-using.html

    An alternative is AJAX, but at the end of the story it is a postback-like approach.

    Finally using postback you can do it in several ways by dynamically setting the GridView filter before the GridView loads. This can be achieved with the Page load event, the OnSelecting of the associated datasource (if any), or similar.

    Here it is an extraction of the aspx:

    <asp:CheckBox ID="CheckBox1" runat="server" Text="A" />
    <asp:CheckBox ID="CheckBox2" runat="server" Text="B" />
    <asp:CheckBox ID="CheckBox3" runat="server" Text="C" />
    <asp:CheckBox ID="CheckBox4" runat="server" Text="D" />
    <hr />
    
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        DataSourceID="sqlDataSourceGridView" AutoGenerateColumns="False"
        CssClass="GridViewStyle" GridLines="None" Width="650px" >
        <Columns> 
            <asp:BoundField DataField="CompanyName" HeaderText="Company" ItemStyle-Width="200px" />
            <asp:BoundField DataField="ContactName" HeaderText="Name" ItemStyle-Width="125px"/>
            <asp:BoundField DataField="City" HeaderText="city" ItemStyle-Width="125px" />
            <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="125px" />
        </Columns>
    </asp:GridView>
    
    <asp:SqlDataSource ID="SqlDataSourceGridView" runat="server" 
        ConnectionString="<%$ ConnectionStrings:northWindConnectionString %>" 
        SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [City], [Country] FROM [Customers]" 
        OnSelecting="SqlDataSourceGridView_Selecting">
     <FilterParameters>
        <asp:ControlParameter ControlID="checkbox1" Name="CompanyName" PropertyName="Checked" ConvertEmptyStringToNull="false" />
     </FilterParameters>
    </asp:SqlDataSource>
    

    Note the OnSelecting event and note that there isn’t any filter preset.

    Now in the code behind set dynamically the filter:

    protected void SqlDataSourceGridView_Selecting(object sender, SqlDataSourceSelectingEventArgs e) {
        SqlDataSourceGridView.FilterExpression = string.Empty;
        if (CheckBox1.Checked) {
            SqlDataSourceGridView.FilterExpression += "(CompanyName=1)";
        }
        if (CheckBox2.Checked) {
            if (!string.IsNullOrEmpty(SqlDataSourceGridView.FilterExpression)) SqlDataSourceGridView.FilterExpression += " OR ";
            SqlDataSourceGridView.FilterExpression += "(B=1)";
        }
        if (CheckBox3.Checked) {
            if (!string.IsNullOrEmpty(SqlDataSourceGridView.FilterExpression)) SqlDataSourceGridView.FilterExpression += " OR ";
            SqlDataSourceGridView.FilterExpression += "(C=1)";
        }
        if (CheckBox4.Checked) {
            if (!string.IsNullOrEmpty(SqlDataSourceGridView.FilterExpression)) SqlDataSourceGridView.FilterExpression += " OR ";
            SqlDataSourceGridView.FilterExpression += "(D=1)";
        }
    }
    

    If you don’t like the OnSelecting event, you can do the same in the PageLoad:

    protected void Page_Load(object sender, EventArgs e) {
        // here same code of above
        // . . .
    }
    

    I didn’t test it so verify minor errors.

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

Sidebar

Related Questions

hello friends i have a check box list which contains all the courses kept
INSERT MODE i have check box in one tr. and another dropdown control in
I have a check box, RequiredFieldValidator and textbox that have editmask extender I want
I have a check box and I have subscribed for the CheckedChanged event. The
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
hi i have two xml file and i want to bind grid view eith
I have a simple ASP page with databound grid (bound to an object source).
So I have a grid view with checkboxes in it. This is the code
Hi i have application where i have to export grid data on a page
I am using two gridview controls in my aspx page. And I have a

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.