This example demonstrates how to set the size of the Grid View control to the size of the browser window.
Overview
Follow the steps below to display the ASPxGridView control in the full screen mode.
1. Remove Margins
Set the body
element's paddings and margins to zero.
CSSbody, html {
padding: 0;
margin: 0;
}
2. Add a Vertical Scroll Bar
Set the VerticalScrollBarMode property to Visible
to show the vertical scrollbar.
ASPx<dx:ASPxGridView runat="server" ID="gridView" ClientInstanceName="grid" Width="100%" DataSourceID="ds" KeyFieldName="OrderID">
<SettingsPager PageSize="50" />
<Settings VerticalScrollBarMode="Visible" VerticalScrollableHeight="0" />
</dx:ASPxGridView>
3. Set the Control's Height
Handle the Init and EndCallback events and call the SetHeight method to adjust the Grid View's height during initialization and after each callback.
ASPxfunction OnInit(s, e) {
AdjustSize();
}
function OnEndCallback(s, e) {
AdjustSize();
}
function AdjustSize() {
var height = Math.max(0, document.documentElement.clientHeight);
grid.SetHeight(height);
}
<dx:ASPxGridView runat="server" ID="gridView" ClientInstanceName="grid" Width="100%" DataSourceID="ds" KeyFieldName="OrderID">
<!-- ... --->
<ClientSideEvents Init="OnInit" EndCallback="OnEndCallback" />
</dx:ASPxGridView>
4. Hide the Resizing from Users
Place the ASPxGridView in a hidden container and show the container after initialization is completed.
ASPxfunction OnInit(s, e) {
// ...
document.getElementById("gridContainer").style.visibility = "";
}
<div id="gridContainer" style="visibility: hidden">
<dx:ASPxGridView runat="server" ID="gridView" ClientInstanceName="grid" Width="100%" DataSourceID="ds" KeyFieldName="OrderID">
<!-- ... --->
</dx:ASPxGridView>
</div>
Files to Look At
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
Documentation
More Examples
- Grid View for ASP.NET MVC - How to display the Grid View in the full screen mode
- Page Control for ASP.NET Web Forms - How to display the Page Control in the full screen mode
Example Code
ASPx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v21.2, Version=21.2.13.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dx" %>
<!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>
<style type="text/css">
body, html {
padding: 0;
margin: 0;
}
</style>
<script type="text/javascript">
function OnInit(s, e) {
AdjustSize();
document.getElementById("gridContainer").style.visibility = "";
}
function OnEndCallback(s, e) {
AdjustSize();
}
function OnControlsInitialized(s, e) {
ASPxClientUtils.AttachEventToElement(window, "resize", function (evt) {
AdjustSize();
});
}
function AdjustSize() {
var height = Math.max(0, document.documentElement.clientHeight);
grid.SetHeight(height);
}
</script>
</head>
<body style="overflow: hidden">
<form id="form1" runat="server">
<div id="gridContainer" style="visibility: hidden">
<dx:ASPxGridView runat="server" ID="gridView" ClientInstanceName="grid" AutoGenerateColumns="true"
Width="100%" DataSourceID="ds" KeyFieldName="OrderID" OnHtmlRowCreated="gridView_HtmlRowCreated">
<SettingsPager PageSize="50" />
<Settings VerticalScrollBarMode="Visible" VerticalScrollableHeight="0" />
<ClientSideEvents Init="OnInit" EndCallback="OnEndCallback" />
</dx:ASPxGridView>
</div>
<asp:AccessDataSource ID="ds" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT TOP 200 * FROM [Orders]"></asp:AccessDataSource>
<dx:ASPxGlobalEvents ID="ge" runat="server">
<ClientSideEvents ControlsInitialized="OnControlsInitialized" />
</dx:ASPxGlobalEvents>
</form>
</body>
</html>