2013-06-04 72 views
0

我有一個gridView和兩個複選框,將用於篩選.. 第一個複選框(接受),當選中時,gridview將只顯示數據庫中的狀態爲Accepted的數據。使用複選框篩選gridview

這裏是我的GridView和複選框:

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

我怎樣才能做到這一點使用JavaScript? 謝謝...

+0

你正在使用asp.net,爲什麼它js,如果它的10倍容易在vb/c# – DiederikEEn

回答

1

您可以使用gridview'onrowdatabound和DataKeyNames'的以下屬性。 在DataKeyNames中,您可以通過數據讀取器給出您正在通過數據庫讀取的類變量或屬性的名稱。

火你的GridView的RowDataBound事件,以便您可以檢查狀態

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. 
         . 
         . 
        } 
    } 
0

您可以創建2個網格視圖和時的相關網格視圖綁定選中複選框之一。