Demonstrates how to bind jqGrid to declarative ObjectDataSource control. The only thing you need to do is to set the DataSourceID property of jqGrid to the ID of the respective ObjectDataSource control. Note that there is not even a single line of code in the C# file (click on the C# tab) - everything is done declaratively.

Also, all major grid features like sorting (click on a column header), searching (click on the server icon on the bottom toolbar), paging, etc work as well by default -- no need to code anything.

Column settings can be customized using the collection. Columns are automatically created when you associate a declarative datasource with the grid at design time.

You can tweak various column properties, like HeaderText (in order to set column header text), DataFormatString (to control formatting of the cells), Width (set column with in pixels), etc.



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

///
/// Summary description for DataAccess
///

public class DataAccess
{
public DataAccess()
{

}
///
/// This method is used by the object data source to get a generic list
/// of objects to bind to.
///

///
///
///
public static List GetData(string p_sortExpression, string p_sortDirection)
{
List peoples = new List();
//Normally here you would access your database to populate this object.
//Since I want this example not to have any need to connect to a data base
//I am just creating the data.
//Note when caching the objectdatasource a chance in parameters being
//passed in will case the select method to be called again.
#region Creating data
peoples.Add(new People(1, "Bart", "Long", "Mower", 10.00M, 18));
peoples.Add(new People(2, "Al", "Short", "Garbage Man", 18.00M, 23));
peoples.Add(new People(3, "Phil", "Whinner", "Construction", 23.50M, 22));
peoples.Add(new People(4, "Bill", "Moan", "Painter", 15.25M, 28));
peoples.Add(new People(5, "William", "Best", "Consultant", 50.00M, 30));
peoples.Add(new People(6, "Harry", "Whiler", "Student", 0M, 19));
peoples.Add(new People(7, "Grace", "Finny", "Store Clerk", 11.50M, 24));
peoples.Add(new People(8, "Mary", "Willams", "Cell Phone Sales", 19.50M, 32));
peoples.Add(new People(9, "Jim", "Green", "Teacher", 13.75M, 27));
peoples.Add(new People(10, "Bob", "RedMan", "Construction", 25.50M, 35));
peoples.Add(new People(11, "Larry", "Quinn", "Actor", 16.00M, 22));
peoples.Add(new People(12, "Alex", "Zare", "Construction", 21.25M, 21));
peoples.Add(new People(13, "Sue", "Andersen", "Waitress", 11.75M, 26));
peoples.Add(new People(14, "Rita", "Don Diego", "Home maker", 0M, 36));
peoples.Add(new People(15, "Barry", "Cline", "Repair Man", 19.50M, 40));
peoples.Add(new People(16, "Tyler", "Huge", "Teacher", 15.50M, 31));
peoples.Add(new People(17, "Martha", "Smith", "Pre-School Teacher", 12.25M, 38));
peoples.Add(new People(18, "Mark", "Dalton", "Cook", 14.50M, 35));
peoples.Add(new People(19, "George", "Larson", "Banker", 30.00M, 45));
peoples.Add(new People(20, "Tara", "Thomas", "Nurse", 22.00M, 24));
peoples.Add(new People(21, "Gary", "Black", "Doctor", 46.50M, 29));
#endregion

//We sort the generic list if requested too
if (p_sortExpression != null && p_sortExpression != string.Empty)
{
peoples.Sort(new PeopleComparer(p_sortExpression));
}

//Now that we have sorted check to see if the sort direction is desc
if (p_sortDirection != null && p_sortDirection == "Desc")
{
peoples.Reverse();
}


return peoples;
}
}



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for People
///

public class People : ICloneable
{
#region Constructors
///
/// We have a generic list of this type in our example
///

public People()
{ }
public People(int p_key, string p_firstName, string p_lastName, string p_skills,
decimal p_dollarsPerHour, int p_age)
{
this.Key = p_key;
this.Age = p_age;
this.DollarsPerHour = p_dollarsPerHour;
this.FirstName = p_firstName;
this.LastName = p_lastName;
this.Skills = p_skills;
}
#endregion

#region Properties
private int _key;

public int Key
{
get { return _key; }
set { _key = value; }
}
private string _firstName;

public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}

private string _lastName;

public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

private string _skills;

public string Skills
{
get { return _skills; }
set { _skills = value; }
}

private decimal _dollarsPerHour;

public decimal DollarsPerHour
{
get { return _dollarsPerHour; }
set { _dollarsPerHour = value; }
}

private int _age;

public int Age
{
get { return _age; }
set { _age = value; }
}
#endregion

#region ICloneable Members

public Object Clone()
{
People people = new People();
people.Key = this.Key;
people.Age = this.Age;
people.DollarsPerHour = this.DollarsPerHour;
people.FirstName = this.FirstName;
people.LastName = this.LastName;
people.Skills = this.Skills;

return people;
}

#endregion
}


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JQSuiteASPNETExample.examples.loading_data.objectdatasource._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 - load data from ObjectDataSource</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 ID="ObjectDataSourceGrid" runat="server" width="500px" DataSourceID="ObjectDataSource1">        
        <Columns>
            <trirand:JQGridColumn DataField="Key" PrimaryKey="true" Sortable="false" />
            <trirand:JQGridColumn DataField="Age" Sortable="false" />
            <trirand:JQGridColumn DataField="DollarsPerHour" Sortable="false"/>
            <trirand:JQGridColumn DataField="LastName" Sortable="false"/>
            <trirand:JQGridColumn DataField="FirstName" Sortable="false"/>
        </Columns>
    </trirand:JQGrid>
    
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  SelectMethod="GetData" TypeName="DataAccess" CacheDuration="300" CacheExpirationPolicy="Sliding">
        <SelectParameters>
            <asp:Parameter Name="p_sortExpression" Type="string" Direction="input" />
            <asp:Parameter Name="p_sortDirection" Type="string" Direction="input" />
        </SelectParameters>
    </asp:ObjectDataSource>
   
    <br /><br />
    <trirand:codetabs runat="server" id="ObjectDataSourceTabs"></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.loading_data.objectdatasource
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
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" />