Click here to Skip to main content
Click here to Skip to main content

Userful GridView ASP.NET

, 31 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
I tried to summrize the common feature which we generally want in GridView.


I tried to summrize the common feature which we generally want in GridView.

  1. Fixed hedder and scrollbar – using jQuery
  2. Check Uncheck all rows - using jQuery
  3. Sorting direction imgae indicator - just by code behind no CSS no Script
  4. Filter GridView row at client side - javascript

Using the code

This is just a code snips so it will not run at you end you need to include this codes to your project and probably need to make necessarily changes.

You need to include the jquery-1.4.4.min.js and ScrollableGridPlugin.js" in you prject. (I am uploding that with this article)

1. Fixed hedder and scrollbar – using jQuery



<script src="../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../Scripts/ScrollableGridPlugin.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">

       // Check/ Uncheck all
        $(window).bind('load', function () {
            var headerChk = $(".chkHeader input");
            var itemChk = $(".chkItem input");
            headerChk.bind("click", function () {
                itemChk.each(function () { this.checked = headerChk[0].checked; })
            itemChk.bind("click", function () { if ($(this).checked == false) headerChk[0].checked = false; });

        // Fixing the hear for Scroll
       $(document).ready(function () {
            //Invoke Scrollable function.
            $('#<%=SearchResult.ClientID %>').Scrollable({
                ScrollHeight: 600,        

         //GV runtime filter
        function filter (term, GvId,SearchOn)
            var SearchOn ='#'+SearchOn;
            var cellNr = $(SearchOn).find('input:checked').val();
            var suche = term.value.toLowerCase();
            var table = document.getElementById(GvId);
            var ele;
            for (var r = 0; r < table.rows.length; r++)
                ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
                if (ele.toLowerCase().indexOf(suche)>=0 )
                    table.rows[r].style.display = '';
                else table.rows[r].style.display = 'none';


Code Behind: 
protected void Page_Load(object sender, EventArgs e)

            if (!IsPostBack)
                ViewState[FixInfo.SortColum] = " ";
                ViewState[FixInfo.SortDirection] = " ";

                //for GV runtime filter
                SearchTxt.Attributes.Add("onkeyup", "filter(this,'" + SearchResult.ClientID + "','" 
                    + SearchOn.ClientID + "')");

        catch (Exception ex)


    protected void SearchResult_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.Header)
            foreach (TableCell tc in e.Row.Cells)
                if (ViewState[FixInfo.SortDirection].ToString().Length > 2)
                        LinkButton lnkBtn = (LinkButton)tc.Controls[0];

                        if (lnkBtn != null)
                            if (ViewState[FixInfo.SortColum].ToString().Equals(lnkBtn.CommandArgument, StringComparison.InvariantCultureIgnoreCase))
                                System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();

                                img.ImageUrl = "~/Images/" + ViewState[FixInfo.SortDirection].ToString() + ".gif";




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Himanshu Thawait
Technical Lead Cognizant
United States United States
Himanshu Thawait is from Pune INDIA, He is Currently Working with Cognizant. As a Technical Designer

Himanshu has more than 9+ yrs of experience in the IT industry working on Microsoft Technologies. He is involved in various project activities like designing the system and technical architecture,leading technical front and doing core development.He also has strong knowledge of Enterprise Business Application Domain.

Technical experience :C#, ASP.NET MVC 4 @Razor, WCF and Webservices, Biztalk 2010/2009/2006R2 with EDI(HIPPA).

Comments and Discussions

GeneralMy vote of 5 Pinmembermanoj kumar choubey30-Jun-14 2:33 
QuestionRequest for entire code PinmemberBridewin17-Apr-13 3:54 
AnswerRe: Request for entire code PinmemberHimanshu Thawait17-Apr-13 5:53 
GeneralMy vote of 1 PinmemberMember 948470624-Dec-12 23:55 
GeneralRe: My vote of 1 PinmemberHimanshu Thawait27-Dec-12 7:06 
Questiongood move PinmemberMr. Tapan Kumar10-Oct-12 10:56 
GeneralMy vote of 2 PinmemberMr. Tapan Kumar10-Oct-12 10:55 
good onee
GeneralMy vote of 5 PinmemberCS140111-Mar-12 19:18 
Questiondisplay mysqldata on gridview Pinmembersmp 23429-Feb-12 23:19 
QuestionMissing functions PinmemberPaul M Cohen7-Feb-12 10:25 
AnswerRe: Missing functions Pinmemberthawait.himanshu8-Feb-12 6:47 
GeneralRe: Missing functions PinmemberPaul M Cohen8-Feb-12 10:04 
GeneralRe: Missing functions Pinmemberthawait.himanshu8-Feb-12 12:05 
GeneralRe: Missing functions PinmemberPaul M Cohen8-Feb-12 17:52 PinmemberEmad Mokhtar1-Feb-12 13:07 
GeneralRe: PinmemberJason Vogel1-Feb-12 17:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.1 | Last Updated 31 Jan 2012
Article Copyright 2012 by Himanshu Thawait
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid