> jqGrid for ASP.NET WebForms - Frozen Columns


Select number of frozen columns:




You can freeze the first N number of columns in a grid - so that when the user scrolls the grid horizontally, the first N columns stay frozen. Just set the Frozen property of the respective columns to true and this is all you need. In order to see a horizontal scrollbar, you need to set Width of the grid to a smaller number than the combined Width properties of all columns in the grid.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JQSuiteASPNETExample.examples.grid.functionality.frozen_columns._default" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>

<!DOCTYPE html>
<html lang="en-us">>
<head id="Head1" runat="server">
    <meta charset="utf-8">
    <title>jqGrid for ASP.NET WebForms - Frozen Columns</title>
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="http://code.jquery.com/ui/1.12.1/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <!-- The localization file we need, English in this case -->
    <script src="/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="/js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>    
    
    <style type="text/css">    
        body, html { font-size: 80%; }    
    </style>
</head>
<body>
    <form id="form1" runat="server">    
        
    <trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="LinqDataSource1" Width="650" Height="100%">
        <Columns>
            <trirand:JQGridColumn DataField="CustomerID" PrimaryKey="true" Width="60" Frozen="true" />
            <trirand:JQGridColumn DataField="CompanyName" Width="150" Frozen="true" />
            <trirand:JQGridColumn DataField="ContactName"  Width="150" />
            <trirand:JQGridColumn DataField="ContactTitle" Width="120"/>
            <trirand:JQGridColumn DataField="Address" Width="120" />
            <trirand:JQGridColumn DataField="City" Width="120" />
            <trirand:JQGridColumn DataField="Region" Width="120" />
            <trirand:JQGridColumn DataField="PostalCode" Width="120" />
            <trirand:JQGridColumn DataField="Country" Width="120" />
            <trirand:JQGridColumn DataField="Phone" Width="120" />
            <trirand:JQGridColumn DataField="Fax" Width="120" />
        </Columns>        
    </trirand:JQGrid>  
    
    <br />
    <br />    
    
    <div style="font-size:125%; font-family:Verdana">
        Select number of frozen columns:    
        <br />
        <asp:RadioButtonList ID="FrozenColumnsRbl" AutoPostBack="true" runat="server" 
            onselectedindexchanged="FrozenColumnsRbl_SelectedIndexChanged">
            <asp:ListItem Text="Freeze first olumn" Value="1" />
            <asp:ListItem Text="Freeze first 2 columns" Value="2" Selected="True" />
            <asp:ListItem Text="Freeze first 3 columns" Value="3" />
        </asp:RadioButtonList>
    </div>
    
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        AutoPage="true" AutoSort="true"
        ContextTypeName="JQSuiteASPNETExample.dbml.NorthWindDataClassesDataContext" 
        Select="new (CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)"         
        TableName="Customers">
    </asp:LinqDataSource>    
    
    <br /><br />
    <trirand:codetabs runat="server" id="tabs"></trirand:codetabs>  
    
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JQSuiteASPNETExample.examples.grid.functionality.frozen_columns
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void FrozenColumnsRbl_SelectedIndexChanged(object sender, EventArgs e)
        {
            int frozenColumns = Convert.ToInt16(FrozenColumnsRbl.SelectedValue);
            for (int i = 0; i < JQGrid1.Columns.Count; i++)
            {
                if (i < frozenColumns)
                    JQGrid1.Columns[i].Frozen = true;
                else
                    JQGrid1.Columns[i].Frozen = false;
            }
        }
    }
}
Switch theme:


Theming is based on the very popular jQuery ThemeRoller standard. This is the same theming mechanism used by jQuery UI and is now a de-facto standard for jQuery based components. The benefits of using ThemeRoller are huge. We can offer a big set of ready to use themes created by professional designers, including Windows-like themes (Redmond), Apple-like theme (Cupertino), etc. In addition to that any jQuery UI controls on the same page will pick the same theme.

Last, but not least, you can always roll your own ThemeRoller theme, using the superb Theme Editor

To use a theme, simply reference 2 Css files in your Html <head> section - the ThemeRoller theme you wish to use, and the jqGrid own ThemeRoller Css file. For example (Redmond theme):

<link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />