Home > ASP.Net > Search row in Gridview (Alphaptical)

Search row in Gridview (Alphaptical)


try this example

<%@ page autoeventwireup="true" codefile="FilterWithAlphabetLinkButtons.aspx.cs"
 inherits="GridView_FilterWithAlphabetLinkButtons" language="C#" masterpagefile="~/MasterPages/Default.master"
 title="GridView: Filter With Alphabet LinkButtons" %>

<asp:content id="Content1" runat="Server" contentplaceholderid="ContentPlaceHolder1">
 <asp:linkbutton id="btnAll" runat="server" text="ALL" onclick="btnAll_Click" />
 <asp:repeater id="rptLetters" runat="server" datasourceid="sdsLetters">
   <asp:linkbutton id="btnLetter" runat="server" onclick="btnLetter_Click" text='<%#Eval("Letter")%>' />
 <asp:sqldatasource id="sdsLetters" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
  selectcommand="SELECT DISTINCT LEFT(ProductName, 1) AS [Letter] FROM [Products]">
 <asp:gridview id="gvProducts" runat="server" datakeynames="ProductID" datasourceid="sdsProducts"
  style="margin-top: 12px;">
 <asp:sqldatasource id="sdsProducts" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
  selectcommand="SELECT ProductID, ProductName FROM [Products] ORDER BY [ProductName]">


using System;
using System.Web.UI.WebControls;

public partial class GridView_FilterWithAlphabetLinkButtons : System.Web.UI.Page
  protected void btnAll_Click(object sender, EventArgs e)

 protected void btnLetter_Click(object sender, EventArgs e)
  LinkButton btnLetter = sender as LinkButton;

  if (btnLetter == null) { return; }

  sdsProducts.SelectCommand = String.Format(
   "SELECT ProductID, ProductName FROM [Products] WHERE ([ProductName] LIKE '{0}%') ORDER BY [ProductName]",

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: