<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JQSuiteASPNETExample.examples.grid.exporting.excel._default" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<!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 id="Head1" runat="server">
<title>jqGrid ASP.NET - Export to Excel</title>
<!-- The jQuery UI theme that will be used by the grid -->
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/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="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.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>
<!-- This jQuery UI library is needed only for the code tabs, not needed by the grid per se -->
<script src="/js/trirand/jquery.jqDatePicker.min.js" type="text/javascript"></script>
<script src="/js/trirand/jquery.jqAutoComplete.min.js" type="text/javascript"></script>
<style type="text/css">
body, html { font-size: 80%; }
.ui-autocomplete-loading { background: white url('loading.gif') right center no-repeat; }
</style>
</head>
<body>
<form id="form1" runat="server">
<trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="LinqDataSource1"
Width="600px" onsearching="JQGrid1_Searching" >
<Columns>
<trirand:JQGridColumn
DataField="OrderID"
Searchable="true"
SearchToolBarOperation="IsEqualTo"
DataType="Int"
HeaderText="Order ID"
PrimaryKey="True"
Width="50" />
<trirand:JQGridColumn
DataField="CustomerID"
DataType="String"
SearchType="DropDown"
SearchControlID="DropDownList1"
SearchToolBarOperation="IsEqualTo" />
<trirand:JQGridColumn
DataField="OrderDate"
Searchable="true"
SearchType="DatePicker"
SearchControlID="DatePicker1"
SearchToolBarOperation="IsEqualTo"
DataType="DateTime"
DataFormatString="{0:yyyy-MM-dd}"/>
<trirand:JQGridColumn
DataField="Freight"
DataType="Decimal"
SearchType="DropDown"
SearchValues="[All]:[All];10:> 10;20:> 20;30:> 30;50:> 50"
SearchToolBarOperation="IsGreaterThan" />
<trirand:JQGridColumn
Searchable="true"
DataType="String"
SearchType="AutoComplete"
SearchControlID="AutoComplete1"
SearchToolBarOperation="Contains"
DataField="ShipName"
Width="200" />
</Columns>
<ExportSettings ExportDataRange="All" />
<ToolBarSettings ShowSearchToolBar="true"/>
</trirand:JQGrid>
<br /><br />
<asp:RadioButtonList runat="server" ID="ExportType"
style="font-size: 125%; font-family: Tahoma;" >
<asp:ListItem Text="Export All Data" Value="1"></asp:ListItem>
<asp:ListItem Text="Export Only Filtered Data" Value="2"></asp:ListItem>
<asp:ListItem Text="Export Only Filtered & Paged Data" Value="3"></asp:ListItem>
</asp:RadioButtonList>
<br /><br />
<asp:Button runat="server" ID="ExportToExcelButton" Text="Export to Excel" OnClick="ExportToExcelButton_Click" />
<%-- This control will be used as a DatePicker search UI control in the grid toolbar--%>
<%-- You can use JQDatePicker as a standalone control outside of a grid by setting DisplayMode="Standalone" --%>
<trirand:JQDatePicker
DisplayMode="ControlEditor"
runat="server"
ID="DatePicker1"
DateFormat="yyyy-MM-dd"
MinDate="2010-01-01"
MaxDate="2020-01-01"
ShowOn="Focus" />
<%-- This control will be used as an AutoComplete search UI control in the grid toolbar--%>
<%-- You can use JQAutoComplete as a standalone control outside of a grid by setting DisplayMode="Standalone" --%>
<trirand:JQAutoComplete
DisplayMode="ControlEditor"
DataTextField="ShipName"
DataSourceID="SqlDataSource1"
runat="server"
ID="AutoComplete1"
/>
<%--This control will be used as a DropDown search UI control in the grid toolbar--%>
<asp:DropDownList
runat="server"
ID="DropDownList1"
DataSourceID="SqlDataSource2"
DataTextField="CustomerID"
DataValueField="CustomerID"
AppendDataBoundItems="true">
<asp:ListItem Text="[All]" Value="[All]"></asp:ListItem>
</asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
AutoPage="true" AutoSort="true"
ContextTypeName="GridTest.dbml.NorthWindDataClassesDataContext"
Select="new (OrderID, OrderDate, ShipName, CustomerID, Freight)"
TableName="Orders">
</asp:LinqDataSource>
<asp:SqlDataSource runat="server" ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:SQL2008_449777_fhsConnectionString %>"
SelectCommand="SELECT [OrderID], [RequiredDate], [ShipName], [ShipCity], [Freight] FROM [Orders]">
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="SqlDataSource2"
ConnectionString="<%$ ConnectionStrings:SQL2008_449777_fhsConnectionString %>"
SelectCommand="SELECT DISTINCT [CustomerID] FROM [Orders]">
</asp:SqlDataSource>
<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;
using Trirand.Web.UI.WebControls;
namespace JQSuiteASPNETExample.examples.grid.exporting.excel
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object send, EventArgs args)
{
if (JQGrid1.AjaxCallBackMode != AjaxCallBackMode.None)
{
// save the last grid state in session - to be used for exporting
Session["gridFilterPageState"] = JQGrid1.GetState();
}
}
protected void JQGrid1_Searching(object sender, Trirand.Web.UI.WebControls.JQGridSearchEventArgs e)
{
if (e.SearchString == "[All]")
e.Cancel = true;
}
protected void ExportToExcelButton_Click(object sender, EventArgs e)
{
JQGridState gridState = Session["gridFilterPageState"] as JQGridState;
switch (ExportType.SelectedValue)
{
case "1":
JQGrid1.ExportSettings.ExportDataRange = ExportDataRange.All;
JQGrid1.ExportToExcel("export.xls");
break;
case "2":
JQGrid1.ExportSettings.ExportDataRange = ExportDataRange.Filtered;
JQGrid1.ExportToExcel("export.xls", gridState);
break;
case "3":
JQGrid1.ExportSettings.ExportDataRange = ExportDataRange.FilteredAndPaged;
JQGrid1.ExportToExcel("export.xls", gridState);
break;
}
}
}
}
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" />