<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .headingText
        {
            font-size: 18pt;
            font-weight: bold;
            text-decoration: underline;
        }
        .topBar
        {
            border: solid 2px #555555;
            text-align: center;
            background-color: #aaaaaa;
            padding-bottom: 10px;
        }
        .wrapper
        {
            background-color: #333333;
            width: 100%;
            height: 550px;
            border: solid 2px black;
        }
    </style>
</head>
<body>
    <form id="Form1" runat="server">
    <telerik:RadScriptManager ID="ScriptManager1" runat="server" />

       
        <telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
        function getOuterHTML(obj) {
            if (typeof (obj.outerHTML) == "undefined") {
                var divWrapper = document.createElement("div");
                var copyOb = obj.cloneNode(true);
                divWrapper.appendChild(copyOb);
                return divWrapper.innerHTML
            }
            else
                return obj.outerHTML;
        }

        function PrintRadGrid() {
            var previewWnd = window.open('about:blank', '', '', false);
            var sh = '<%= ClientScript.GetWebResourceUrl(radGrid1.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radGrid1.Skin)) %>';
            var shBase = '<%= ClientScript.GetWebResourceUrl(radGrid1.GetType(),"Telerik.Web.UI.Skins.Grid.css") %>';
            var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
            styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
            var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= radGrid1.ClientID %>').get_element()) + "</body></html>";
            previewWnd.document.open();
            previewWnd.document.write(htmlcontent);
            previewWnd.document.close();
            previewWnd.print();

            if (!$telerik.isChrome) {
                previewWnd.close();
            }
        }
    </script>
        </telerik:RadCodeBlock>
    <div class="wrapper">
        <div class="topBar">
            
                <asp:Button Text="PrintGrid" OnClick="Unnamed_Click" runat="server" />
           
            This code-library demonstrates how to print RadGrid without surrounding content<br />
        </div>
        <telerik:RadGrid ID="radGrid1" runat="server" Skin="Simple" DataSourceID="SqlDataSource1"
            Style="margin: 20px;" AllowPaging="True" OnItemCommand="radGrid1_ItemCommand" AllowSorting="True" PageSize="50" AllowFilteringByColumn="True"
            GridLines="None">
        </telerik:RadGrid>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [ProductID], [ProductName], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued] FROM [Products]">
    </asp:SqlDataSource>
    </form>
</body>
</html>

