Here is a code example of searching a GridView control in ASP.NET.
Create an ASP.NET Web Application using Visual Studio.
Step 1: Download ziped Bin folder and copy it to your Bin folder
Step 2: Add dll to your toolbox and drag it to your web page.
Step 3: Now, change the default aspx page. I add some controls to the page. See below.
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <%@ Register assembly="SamApp.WebControls.SearchGridView" namespace="SamApp.WebControls" tagprefix="cc1" %>
- <!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 id="Head1" runat="server">
- <title></title>
- </head>
- <body>
- <p>
- <br />
- </p>
- <form id="form1" runat="server">
- <div style="height: 100px">
- <asp:HiddenField ID="hfSearchText" runat="server" />
- <asp:HiddenField ID="hfSort" runat="server" />
- </div>
- <div>
- <cc1:SearchGridView ID="SearchGridView1" runat="server" BackColor="White"
- BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
- EnableModelValidation="True"
- onpageindexchanging="SearchGridView1_PageIndexChanging"
- onsearchgrid="SearchGridView1_SearchGrid" ShowFooter="True"
- AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
- onsorting="SearchGridView1_Sorting" ForeColor="Black" GridLines="Vertical">
- <SearchFilters>
- <asp:ListItem>Username</asp:ListItem>
- <asp:ListItem Value="User_Pass">Password</asp:ListItem>
- <asp:ListItem Value="F_Name">First Name</asp:ListItem>
- <asp:ListItem Value="L_Name">Last Name</asp:ListItem>
- <asp:ListItem Value="City">City</asp:ListItem>
- </SearchFilters>
- <AlternatingRowStyle BackColor="#CCCCCC" />
- <Columns>
- <asp:BoundField DataField="Username" HeaderText="Username"
- SortExpression="Username" />
- <asp:BoundField DataField="User_Pass" HeaderText="Password"
- SortExpression="User_Pass" />
- <asp:BoundField DataField="F_Name" HeaderText="First Name"
- SortExpression="F_Name" />
- <asp:BoundField DataField="L_Name" HeaderText="Last Name"
- SortExpression="L_Name" />
- <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
- </Columns>
- <FooterStyle BackColor="#CCCCCC" />
- <HeaderStyle BackColor="#333399" Font-Bold="True" ForeColor="Silver" />
- <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
- </cc1:SearchGridView>
- <br />
- <br />
- </div>
- <div>
- </div>
- </form>
- </body>
- </html>

Join the conversation! Your thoughts help the community grow.