aianLee
aianLee

Reputation: 61

filter gridview using checkbox

I have a gridView and two checkboxes that will be used for filtering.. the first checkbox(Accepted), when checked, the gridview will only show data from the database that have the status Accepted.

Here's my gridview and checkbox:

 <div style="height: 250px; overflow-x: hidden; overflow-y: scroll;" >

    <asp:CheckBox ID="Accepted" runat="server" />
    <asp:CheckBox ID="Pending" runat="server" />
    <asp:CheckBox ID="Rejected" runat="server" />

    <asp:GridView ID="gvtransaction" runat="server" Width="30%" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="5px"  DataKeyNames="id" GridLines="Horizontal" OnRowDataBound="gvtransaction_RowDataBound" OnRowCommand="TransactionStatus">
        <Columns>

            <asp:BoundField DataField="MerchantID" HeaderText="ID" SortExpression="" />
            <asp:BoundField DataField="FirstName" HeaderText="Consumer" SortExpression="" />
            <asp:BoundField DataField="LastName" HeaderText="Name" SortExpression="" />
            <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="" />
            <asp:BoundField DataField="CurrencyName" HeaderText="Account Name" SortExpression="" />
            <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="" />
            <asp:ButtonField ButtonType="Button" CommandName="Accept" HeaderText="Action" ShowHeader="True" Text="Accept" />
            <asp:ButtonField ButtonType="Button" CommandName="Reject" HeaderText="Action" ShowHeader="True" Text="Reject" />

        </Columns>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#007DBB" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#00547E" />
    </asp:GridView>

How can i do this using javascript.? thank you...

Upvotes: 0

Views: 916

Answers (2)

Yassering
Yassering

Reputation: 226

You can create 2 Grid views and when one of the check boxes selected bind the associated grid view.

Upvotes: 0

mck
mck

Reputation: 988

You can use following properties of gridview 'onrowdatabound and DataKeyNames'. In DataKeyNames you can give the name of your class variables or properties where you are reading from database through a datareader.

Fire the rowDatabound event of your gridview so that you can check the status

 protected void gvtransaction_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
      int Status = (int)this.gvtransaction.DataKeys[e.Row.RowIndex].Values[0];
                    if (Status)
                    {
                       .
                      check status values for Accepted, pending and rejected through if else.
                       .
                       .
                    }
    }

Upvotes: 1

Related Questions