Click here to Skip to main content
11,927,422 members (47,056 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked

Resizable ASP.NET Gridview Columns using Jquery

, 14 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip explains how to use jQuery's plug-in colResizable to implement client-side column resizing in an ASP.NET GridView.


This tip explains how to use jQuery's plug-in colResizable to implement client-side column resizing in an ASP.NET GridView.

Using the Code

In addition to colResizable, I also use Jquery cookie plugin to store columns width in a cookie, so that ASP.NET postback won't reset column width. Now, download and include the jQuery, cookie and colResizable JavaScript files as follows:

<script type="text/javascript" src="scripts/jquery-latest.js"/>
<script src="/Scripts/colResizable-1.3.min.js" type="text/javascript"/>
<script src="/Scripts/jquery.cookie.js" type="text/javascript"/>  

Initialize the table width from cookie and colResizable plugin when the document is ready, using the code below:

    if ($.cookie('colWidth') != null) {
        var columns = $.cookie('colWidth').split(',');
        var i = 0;
        $('.GridViewStyle th').each(function () {
        liveDrag: true,
        gripInnerHtml: "<div class='grip'></div>",
        draggingClass: "dragging",
        onResize: onSampleResized
    }); }); 

A callback function onSampleResized will be fired when the user has ended dragging a column anchor altering the previous table layout. It will read columns width and store them in a cookie.

var onSampleResized = function (e) {
    var columns = $(e.currentTarget).find("th");
    var msg = "";
    columns.each(function () { msg += $(this).width() + ","; })
    $.cookie("colWidth", msg);

Here is an ASP.NET Gridview.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
DataKeyNames="Id" GridLines="None" CssClass="GridViewStyle">

The final output can be seen here:


This tip showed how to Resize ASP.NET gridview using Jquery.


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


About the Author

Farooq Kaiser
Software Developer (Senior)
Canada Canada
12+ years of complete software development life cycle experience for web based applications and multi-tier client-server desktop, primarily using LINQ, WCF, WWF, C#, ASP.NET, XML, XSLT, AJAX, Winforms,Visual Basic, JavaScript, JQuery, Google APIs, C++, VB.NET, C, ATL/COM, Open XML. Extensively involved in the requirement analysis, feasibility study, conceptualization, planning, architecture/design, configuration, development, quality assurance, implementation and release of the software products.

You may also be interested in...

Comments and Discussions

QuestionThis script wont works on FF Pin
Member 806778927-Jun-12 0:36
memberMember 806778927-Jun-12 0:36 
AnswerRe: This script wont works on FF Pin
Farooq Kaiser27-Jun-12 8:28
memberFarooq Kaiser27-Jun-12 8:28 
QuestionGreat idea! my vote of 5! but little problems on resizing TemplateFields Pin
stefan999913-Jun-12 1:47
memberstefan999913-Jun-12 1:47 
QuestionGood code!! can these be used with multiple girds on page. Pin
Member 45166824-Jun-12 11:51
memberMember 45166824-Jun-12 11:51 
Can these used with multiple gird on the page ?
AnswerRe: Good code!! can these be used with multiple girds on page. Pin
Farooq Kaiser4-Jun-12 12:40
memberFarooq Kaiser4-Jun-12 12:40 
QuestionGreat idea! 5 from me Pin
gstolarov24-Apr-12 8:49
membergstolarov24-Apr-12 8:49 
GeneralMy vote of 3 Pin
FrewCen15-Apr-12 4:45
memberFrewCen15-Apr-12 4:45 
QuestionCan you attach source code Pin
Dorababu74313-Apr-12 20:12
memberDorababu74313-Apr-12 20:12 
AnswerRe: Can you attach source code Pin
Farooq Kaiser14-Apr-12 13:46
memberFarooq Kaiser14-Apr-12 13:46 
GeneralMy vote of 5 Pin
Justin Cooney13-Apr-12 14:57
memberJustin Cooney13-Apr-12 14:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web03 | 2.8.151126.1 | Last Updated 14 Apr 2012
Article Copyright 2012 by Farooq Kaiser
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid