Column Resizing in GridView


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

Up Next
    Ebook Download
    View all
    Learn
    View all