SIGN UP MEMBER LOGIN:    
ARTICLE

Column Resizing in GridView

Posted by Lion Articles | ASP.NET Programming March 01, 2012
CoolGridView is a web control that extends or enhances the ASP.NET GridView control.
Reader Level:

Column Resizing in GridView

The ASP.NET GridView does not support column resiziing. You must use a third party server control like:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/resizing/defaultcs.aspx
http://demos.devexpress.com/aspxgridviewdemos/Columns/ColumnResizing.aspx
http://ideasparks.codeplex.com/

I recommend using coolgrid control of irespaks.
CoolGridView is a web control that extends or enhances an ASP.NET GridView control to deliver the following features:

  • Display fix column headers, footer and pager
  • Supports scrollable content
  • User-resizeable column widths (New!)
  • Maintains scroll position and column widths after a postback or callback (New!)

You can also make a resizable GridView using jQuery colResizable-1.3.min.js.You can download it from http://quocity.com/colresizable/


Step 1
: Your .aspx page like:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!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></title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery.js" type="text/javascript"></script>
    <script src="Scripts/colResizable-1.3.min.js" type="text/javascript"></script>
</
head>
<
body>
    <form id="form1" runat="server">
    <div class="center">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
            border="0" CellPadding="0" >
            <Columns>
                <asp:BoundField DataField="Empid" HeaderText="Empid">
                    <ItemStyle CssClass="left" />
                </asp:BoundField>
                <asp:BoundField DataField="Empname" HeaderText="Empname">
                    <ItemStyle CssClass="left" />
                </asp:BoundField>
                <asp:BoundField DataField="City" HeaderText="City">
                    <ItemStyle CssClass="left" />
                </asp:BoundField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
    <script type="text/javascript">
       $(function () {            
             $(
'#<%=GridView1.ClientID %>').colResizable({
                liveDrag: 
true,
                gripInnerHtml: 
"<div class='grip'></div>",
                draggingClass: 
"dragging",              
            });
        });     
    
</script>
</
body>
</
html>

Step 2 : Your .cs page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; 
/// <summary>
///
 Summary description for DataHelper
/// </summary>
public class DataHelper
{
    
Employee employee = new Employee();
        
public DataHelper()
         {
                
//
                 // TODO: Add constructor logic here
                 //
         }
    
public List<Employee> GetEmployeeData()
    {     
        
List<Employee> emplist = new List<Employee>();
        
for (int i = 1; i <= 25; i++)
        {
            employee = 
new Employee();
            employee.Empid = i;
            employee.Empname = 
"Employee " + i.ToString();
            employee.City = 
"City Name " + i.ToString();
            emplist.Add(employee);
        }
        
return emplist;        
    }
}

Output:

1111.jpg

1112.jpg

Login to add your contents and source code to this article
share this article :
post comment
 

hi if you use updatepanel then put this javascript. <script type="text/javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(resizegridview); function resizegridview(){ $('#<%=GridView1.ClientID %>').colResizable({ liveDrag: true, gripInnerHtml: "<div class='grip'></div>", draggingClass: "dragging", }); } </script>

Posted by Lion Apr 07, 2012

This code works fine on page load... but stops working when page partially post back.. by using custom paging Kindly mail me solution on my email id ajay.kalyan.ynr@gmail.com

Posted by ajay Kalyan Apr 03, 2012

Thanks for sharing it.

Posted by Abhishek Dubey Mar 01, 2012

You have presented your article very nicely.

Posted by Stephen Johnson Mar 01, 2012

It's a great effort to accomplish such task about resizing of columns in Gridview, So keep it up and thanks for sharing...

Posted by Amit Maheshwari Mar 01, 2012
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Team Foundation Server Hosting
Become a Sponsor