This is a migrated thread and some comments may be shown as answers.

On button Click Print Grid Data

5 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rahul
Top achievements
Rank 1
rahul asked on 15 Mar 2014, 05:33 AM
Hi,
     I Want To Print A Grid Data A4 page on Button Click Event.How Can Do It Client Side Or Server Side.

My Grid Code Is:-

<telerik:RadGrid  ID="gv_UnitWiseCashFlow_Report" runat="server"
                                                AllowFilteringByColumn="True"  AllowSorting="True"
                                                ShowGroupPanel="True" AutoGenerateColumns="False" 
                                                ShowStatusBar="true" onneeddatasource="gv_UnitWiseCashFlow_Report_NeedDataSource"  OnItemCreated="gv_UnitWiseCashFlow_Report_ItemCreated"
onexcelexportcellformatting="gv_UnitWiseCashFlow_Report_ExcelExportCellFormatting" >
                                                <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
                                                        <Pdf PageHeight="210mm" PageWidth="297mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm"
                                                                    BorderStyle="Medium" BorderColor="#666666" PaperSize="A4" >
                                                    </Pdf>                                                       
                                                </ExportSettings>
                                                    <ClientSettings AllowDragToGroup="True" >
                                                        <Scrolling AllowScroll="true" UseStaticHeaders="true"  SaveScrollPosition="true"/>                                                                                   
                                                    </ClientSettings>
                                                    <MasterTableView  AutoGenerateColumns="false" >
                                                    <FilterItemStyle HorizontalAlign="Left" />
                                                        <NoRecordsTemplate>
                                                            <asp:Label ID="lbl_no_record" runat="server" Text="No record exist"></asp:Label>
                                                        </NoRecordsTemplate>
                                                        <Columns>          
                                                                <telerik:GridBoundColumn  DataField="RefNo" DataType="System.String" HeaderText="Unit Ref No" FilterControlAltText="Filter column column" UniqueName="RefNo" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                        
                                                                <telerik:GridBoundColumn  DataField="UnitNo" DataType="System.String" HeaderText="Unit No" FilterControlAltText="Filter column column" UniqueName="UnitNo" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">                                                                                                                                                                                                         
                                                                </telerik:GridBoundColumn>
                                                                 <telerik:GridBoundColumn  DataField="UnitType" DataType="System.String" HeaderText="Unit Type" FilterControlAltText="Filter column column" UniqueName="UnitType" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>
                                                                <telerik:GridBoundColumn  DataField="TenantName" DataType="System.String" HeaderText="Tenant Name" FilterControlAltText="Filter column column" UniqueName="TenantName" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>   
                                                                 <telerik:GridDateTimeColumn DataField="ContractStartDate" HeaderText="Contract Start Date"  FilterControlAltText="Filter column column" UniqueName="ContractStartDate" PickerType="DatePicker" FilterDateFormat="dd/MM/yyyy" DataFormatString="{0:dd/MM/yyyy}"   ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ><ItemStyle Width="15%" /> </telerik:GridDateTimeColumn>     
                                                                <telerik:GridDateTimeColumn DataField="ContractEndDate" HeaderText="Contract End Date" FilterControlAltText="Filter column column" UniqueName="ContractEndDate" PickerType="DatePicker" FilterDateFormat="dd/MM/yyyy" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"><ItemStyle Width="15%" /></telerik:GridDateTimeColumn>                                                                                                                                                              
                                                                <telerik:GridBoundColumn  DataField="Rent" DataType="System.Decimal" HeaderText="Rent" FilterControlAltText="Filter column column" UniqueName="Rent" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                                                                          
                                                                <telerik:GridBoundColumn  DataField="Jan" DataType="System.Decimal" HeaderText="Jan" FilterControlAltText="Filter column column" UniqueName="Jan" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="Feb" DataType="System.Decimal" HeaderText="Feb" FilterControlAltText="Filter column column" UniqueName="Feb" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>
                                                                 <telerik:GridBoundColumn  DataField="March" DataType="System.Decimal" HeaderText="March" FilterControlAltText="Filter column column" UniqueName="March" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="April" DataType="System.Decimal" HeaderText="April" FilterControlAltText="Filter column column" UniqueName="April" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>
                                                                 <telerik:GridBoundColumn  DataField="May" DataType="System.Decimal" HeaderText="May" FilterControlAltText="Filter column column" UniqueName="May" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="Jun" DataType="System.Decimal" HeaderText="Jun" FilterControlAltText="Filter column column" UniqueName="Jun" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>
                                                                 <telerik:GridBoundColumn  DataField="July" DataType="System.Decimal" HeaderText="July" FilterControlAltText="Filter column column" UniqueName="July" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="Aug" DataType="System.Decimal" HeaderText="Aug" FilterControlAltText="Filter column column" UniqueName="Aug" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>   
                                                                  <telerik:GridBoundColumn  DataField="Sep" DataType="System.Decimal" HeaderText="Sep" FilterControlAltText="Filter column column" UniqueName="Sep" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="Oct" DataType="System.Decimal" HeaderText="Oct" FilterControlAltText="Filter column column" UniqueName="Oct" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>
                                                                 <telerik:GridBoundColumn  DataField="Nov" DataType="System.Decimal" HeaderText="Nov" FilterControlAltText="Filter column column" UniqueName="Nov" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>                                                              
                                                                <telerik:GridBoundColumn  DataField="Dec" DataType="System.Decimal" HeaderText="Dec" FilterControlAltText="Filter column column" UniqueName="Dec" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>  
                                                                  <telerik:GridBoundColumn  DataField="Total" DataType="System.Decimal" HeaderText="Total" FilterControlAltText="Filter column column" UniqueName="Total" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >                                                                                                                                 
                                                                </telerik:GridBoundColumn>       
                                                                                                                               
                                                    </Columns>                                                   
                                                    </MasterTableView>                                                                                                        
                                            </telerik:RadGrid>
Please Provide Help Full Solution.

Thanks,
Rahul

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Mar 2014, 05:26 AM
Hi Rahul,

Please take a look at the following code library on Print RadGrid contents.

Thanks,
Princy
0
rahul
Top achievements
Rank 1
answered on 17 Mar 2014, 05:50 AM
Thanks for replay, I Use the given code for print but after print all columns or it related data are not shown, Scroll ,Paging , sorting ,Grouping Massage are showing on print . How can avoid this? Please Provide Help Full Solutions.


Thanks,
Rahul
0
Princy
Top achievements
Rank 1
answered on 18 Mar 2014, 06:11 AM
Hi Rahul,

Please try the following code snippet to print radgrid table only.

ASPX:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function PrintRadGrid(radGrid) {
            setTimeout(function () {
                var previewWnd = window.open('about:blank', '', '', false);
                var styleStr = "<html><head><link href='Styles.css' rel='stylesheet' type='text/css'></link></head>";
                var htmlcontent = styleStr + "<body>" + $find(radGrid).get_element().outerHTML + "</body></html>";
                previewWnd.document.open();
                previewWnd.document.write(htmlcontent);
                previewWnd.document.close();
                previewWnd.print();
                previewWnd.close();
            }, 100);
        }
    </script>
</telerik:RadCodeBlock>
<div class="wrapper">
    <div class="topBar">
        <p class="headingText">
            <asp:LinkButton ID="LinkButton1" runat="server" type="button" Text="[ Print Grid ]" Font-Underline="false" ForeColor="Black" OnClick="LinkButton1_Click" /></p>
    </div>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <telerik:RadGrid ID="radGrid1" runat="server" Skin="Simple" DataSourceID="SqlDataSource1" Style="margin: 20px;" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" PageSize="9" GridLines="None">
    </telerik:RadGrid>
</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>" SelectCommand="SELECT OrderID,ShipCIty,OrderDate,ShipName,CustomerID FROM [Orders]">
</asp:SqlDataSource>

C#:
protected void LinkButton1_Click(object sender, EventArgs e)
{
 radGrid1.AllowPaging = false;
 radGrid1.MasterTableView.AllowFilteringByColumn = false;
 radGrid1.Rebind();
 RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + radGrid1.ClientID + "')");      
}

CSS:
<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>

Thanks,
Princy
0
rahul
Top achievements
Rank 1
answered on 18 Mar 2014, 07:06 AM
Hi Princy,
 Thanks for reply, I use provided code it not work my side , when click on print button that time  print window  not open for print  just open  a new blank tab.

Thanks,
Rahul
0
Princy
Top achievements
Rank 1
answered on 19 Mar 2014, 04:04 AM
Hi Rahul,

Unfortunately I'm not able to replicate the issue at my end. I'm attaching the screenshot of what I obtained.

Thanks,
Princy
Tags
Grid
Asked by
rahul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
rahul
Top achievements
Rank 1
Share this question
or