How to Gridview Header Filtering in Asp.net

by Santhakumar Munuswamy

  Posted on  22 November 2014

  ASP.NET


 

In Asp.net Grid view control use to header row filtering for each column to search condition based on that start with first character for each column data. In this sample grid view filter application to used Linq query concepts and also data bind from the data table objects. It is used to Linq query for filtering purpose such as select statement like operator

GridviewFilterExample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewFilterExample.aspx.cs" Inherits="GridviewFilterExample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Gridview Filter Example</title>
    <link rel="stylesheet" type="text/css" href="gridview.css" media="all" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <table style="width: 640px" border="0" cellpadding="0" cellspacing="6" class="GridviewTable">
        <tr >
            <td style="width: 120px">
                Product ID
            </td>
            <td style="width: 120px">
                Product Name
            </td>
            <td style="width: 120px">
                Product Weight
            </td>
            <td style="width: 120px">
                Product Price
            </td>
            <td style="width: 120px">
                Product Expiry Date
            </td>
         </tr>
          <tr >
                <td style="width: 120px;">
                    <asp:TextBox ID="txtProductId" runat="server" Width="75px"></asp:TextBox>
                    &nbsp;<asp:Button ID="btnProductId" runat="server" Text="Go" 
                        onclick="btnProductId_Click" />
                </td>
                <td style="width: 120px;">
                <asp:TextBox ID="txtProductName" runat="server" Width="75px"></asp:TextBox>
                   &nbsp;<asp:Button ID="btnProductName" runat="server" Text="Go" 
                        onclick="btnProductName_Click" />
                </td>
                <td style="width: 120px;">
                <asp:TextBox ID="txtProductWeight" runat="server" Width="75px"></asp:TextBox>
                    &nbsp;<asp:Button ID="btnProductWeight" runat="server" Text="Go" 
                        onclick="btnProductWeight_Click" />
                </td>
                <td style="width: 130px;">                       
                    <asp:TextBox ID="txtProductPrice" runat="server" Width="75px"></asp:TextBox>
                    &nbsp;<asp:Button ID="btnProductPrice" runat="server" Text="Go" 
                        onclick="btnProductPrice_Click" />
                </td>
                <td style="width: 130px;">                       
                    <asp:TextBox ID="txtProductExpiryDate" runat="server" Width="75px"></asp:TextBox>
                    &nbsp;<asp:Button ID="btnProductExpiryDate" runat="server" Text="Go" 
                        onclick="btnProductExpiryDate_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="5">
                    <asp:GridView ID="gvProductDtls" runat="server" AutoGenerateColumns="False"
                         Width="640px" CssClass="Gridview" ShowHeader="False" >                       
                        <Columns>
                            <asp:BoundField DataField="ProducId" ItemStyle-Width="120px" >
                            <ItemStyle Width="120px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="ProductName" ItemStyle-Width="120px" >
                            <ItemStyle Width="120px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="ProductWeight" ItemStyle-Width="120px" >
                            <ItemStyle Width="120px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="ProductPrice" ItemStyle-Width="130px" >
                            <ItemStyle Width="130px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="ProductExpiryDate" ItemStyle-Width="130px" >
                            <ItemStyle Width="130px"></ItemStyle>
                            </asp:BoundField>
                        </Columns>                       
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

source from my old blog: Read more

 


About the Author
Santhakumar Munuswamy is a seasoned Solution Architect and Most Valuable Professional in Cloud /AI solutions. He has been experienced around 14 years in Solution designing, Software Product Development, Technical Documentation, Project Management for Web and Cloud Applications. He has experience in the IT industry across different domains (Automotive, Telecommunications, Healthcare, Logistics & Warehouse Automation, etc.) with roles in Technical Architect, Genesys Consultant, Technical Lead, Team Lead, and Developer. He has experienced in mentorship and coaching high potential developers.

Follow Me: Facebook, Twitter, Google Plus, LinkedIn
blog comments powered by Disqus


Month List

Community Badges