how to print radgrid while using master content pages and UserControls.

18 posts, 0 answers
  1. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 19 Jan 2011 Link to this post

    Hi I want to print radgrid but its not working when using on a usercontrol and then on master page.

    please help.

    I using the following code in my user control.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="printTestRadgrid.ascx.cs" Inherits="WebUserControls_Employees_printTestRadgrid" %>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
            function PrintRadGrid() {
     
                debugger;
                var previewWnd = window.open('about:blank', '', '', false);
                var sh = '<%= Page.ClientScript.GetWebResourceUrl(radGrid1.GetType(),"Telerik.WebControls.RadControls.Grid.Skins.Default.Styles.css") %>';
                sh = sh.replace("&t", "&t");
                var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
                var htmlcontent = styleStr + "<body>" + window["radGrid1"].Control.innerHTML + "</body></html>";
                htmlcontent = htmlcontent.replace(/<script .*?>(.|\n)*?<\/script>/gi, "")
                previewWnd.document.open();
                previewWnd.document.write(htmlcontent);
                previewWnd.document.close();
                previewWnd.print();
                previewWnd.close();
            }
        </script>
        </telerik:RadCodeBlock>
         
         <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <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>
                This code-library demonstrates how to print RadGrid without surrounding content<br />
            </div>
            <telerik:RadGrid ID="radGrid1" runat="server" DataSourceID="SqlDataSource1" Style="margin: 20px;"
                AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" GridLines="None">
            </telerik:RadGrid>
        </div>
        </telerik:RadAjaxPanel>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mobily_alexmarConnectionString %>"
             
        SelectCommand="SELECT [EmployeeID], [EmployeeNumber], [EmployeeStatus], [EmployeeName], [EmployeeNameArabic], [FatherName], [Gender], [MeritalStatus], [DateOfBirth], [Email], [PrimaryMobile], [SecondaryMobile], [CurrentAddress] FROM [tbl_Employee]">
        </asp:SqlDataSource>



    and in the code behind

     foreach (GridItem item in radGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
                item.Display = false;
      RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + radGrid1.ClientID + "')");

    please tell me soon
    Thanks.


    Also when i use radgrid inside a fieldset the ragrid loses its scrolling property and there will b no scrolling for radgrid.

         
  2. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 19 Jan 2011 Link to this post

    um if you want to print - why not use... Telerik Reports?
    reuse the dataset you bind to the grid
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 20 Jan 2011 Link to this post

    But i want to print the rad grid not the rad reports.
  5. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 23 Jan 2011 Link to this post

    there is no solution for this?
  6. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 25 Jan 2011 Link to this post

    Hello Shahid,

    I have followed your scenario and prepared a sample project for you demonstrating how the desired functionality can be implemented. You can find it attached to this message.

    I hope it helps.

    Best wishes,
    Mira
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  7. shahid Aleem
    shahid Aleem avatar
    32 posts
    Member since:
    Jan 2010

    Posted 25 Jan 2011 Link to this post

    thanks a lot mira, this is what i am looking for.

    Thanks again.
  8. daniel
    daniel avatar
    1 posts
    Member since:
    Aug 2011

    Posted 09 Aug 2011 Link to this post

    Mira,

    Has anything changed since this post regarding support for a more robust printing mechanism for Rad Ajax Grid Controls?
     
    I have evaluated the sample project that you attached in the last post here. I am encountering an issue where only one column out of two (the grid has two) are showing up in the print window. Your solution does work, just not completely in my case. I'm not sure what could be causing the issue. I am not doing anything out of the ordinary. I am binding a strongly typed list of objects to the grid, nothing really custom. Any pointers would be helpful.
  9. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 12 Aug 2011 Link to this post

    Hello Daniel,

    The approach from the Print RadGrid contents code library uses the rendered HTML of the RadGrid, so all rendered columns should be printed.

    If the issue persists, please open a formal support ticket and send us a small working project, demonstrating your full setup and showing the unwanted behavior.
    We will debug it locally and get back to you.

    Kind regards,
    Mira
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  10. stevied
    stevied avatar
    37 posts
    Member since:
    Apr 2007

    Posted 17 Feb 2012 Link to this post

    Hi There,

    This works well for me, but i wondered if there is a way to print 2 related grids. I have a master a child grid, if a user selects a row from the master table then the child grid is shown.

    Is this possible?

    S
  11. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 23 Feb 2012 Link to this post

    Hi Stevie,

    You could try combining the HTML code of both grids using exactly the same approach. Just modify this line and add the contents of the second grid here:
    var htmlcontent = styleStr +
          "<body>" +
          $find('<%= radGrid1.ClientID %>').get_element().outerHTML +
          your grids here +
         "</body></html>";

    Regards,
    Daniel
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  12. Jorge
    Jorge avatar
    12 posts
    Member since:
    Jun 2013

    Posted 12 Feb 2014 in reply to Mira Link to this post

    Hi, 

    How could I modify the code to return all the records and not just the records in the page size? I would still want the grid to display the paging size but when the print button is clicked i would like to return all the records in a new window.

    Thanks.
  13. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Feb 2014 in reply to Jorge Link to this post

    Hi Jorge,

    Please try the following sample code snippet:
    Print-radgrid-table-only

    Thanks,
    Princy
  14. Jorge
    Jorge avatar
    12 posts
    Member since:
    Jun 2013

    Posted 13 Feb 2014 in reply to Princy Link to this post

    Thanks, Princy ... nice and simple!
  15. Jorge
    Jorge avatar
    12 posts
    Member since:
    Jun 2013

    Posted 13 Feb 2014 in reply to Jorge Link to this post

    Actually, I just noticed that code prints all the records to a new window and also changes the original page's grid and displays all records. I would like to maintain the paging on the original grid, but display all records in new window. How can this be done?
  16. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 17 Feb 2014 Link to this post

    Hi Jorge,

    In this case you have to disable the paging, rebind the grid in order to load all the data and then printing the grid. Later on you have to enable the paging again. You could enable it on pageLoad client event by using a fireCommnad() function and specify a custom command.

    Regards,
    Kostadin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  17. Jorge
    Jorge avatar
    12 posts
    Member since:
    Jun 2013

    Posted 19 Feb 2014 in reply to Kostadin Link to this post

    Hi again, 

    Actually there is another way. A colleague of mine pointed out that RadGrid's Excel export supports exporting as HTML, so we can use this to generate the HTML and write it to a new window for example. In other words, when we click on the  print button we change the target of the form to a new pop-up window and then we write the html generated to that window. Here's a snippet of what the print button event handler code would look like:

         protected void btnPrint_Click(object sender, EventArgs e)
        {
            PrintHtml(RadGrid1, this.Response);
        }
     
        protected void PrintHtml(Telerik.Web.UI.RadGrid grid, HttpResponse response)
        {
            grid.MasterTableView.AllowPaging = false;
            grid.MasterTableView.AllowSorting = false;
            grid.MasterTableView.AllowFilteringByColumn = false;
            grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
            grid.ClientSettings.Scrolling.AllowScroll = false;
     
            grid.Rebind();
     
            grid.ExportSettings.ExportOnlyData = true;
            grid.ExportSettings.HideStructureColumns = true;
            grid.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
     
            grid.GridExporting += (s, e) =>
            {
                response.ContentType = "text/html";
                response.Write(e.ExportOutput);
                response.End();
            };
     
            grid.MasterTableView.ExportToExcel();
        }

    and in the markup you would need the following client side code:

    <script>
        $('input[type = "submit"]').click(function () {
            if ($(this).attr('id') == $(<%= btnPrint.ClientID %>).attr('id')) {
                window.open('Print', 'Print', 'menubar=no,height=768,width=1366,resizable=yes,toolbar=no,status=no');
                $('form').attr("target", "Print")
            }
            else {
                $('form').removeAttr("target");
            }
        });
    </script>

    Thanks for your help and hope this helps some one else out.
  18. Asutosh
    Asutosh avatar
    130 posts
    Member since:
    Sep 2013

    Posted 15 Jul 2014 in reply to Mira Link to this post

    hi mira
    i am using radgrid and exporting as print
    its works fine 
    but the problem is that is print only showed data,means if my grid height id 300px and if it has scroll it print only display data
    how can i print whole grid if i have scroll also?
    i have attached error image please check it.
  19. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 17 Jul 2014 Link to this post

    Hi Asutosh,

    You need to disable the scrolling before print the grid. Also if you are using a paging you need to disable it either as Jorge demonstrates in his reply.

    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017