shahid Aleem
Top achievements
Rank 1
shahid Aleem
asked on 19 Jan 2011, 03:27 PM
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.
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.
17 Answers, 1 is accepted
0
Elliott
Top achievements
Rank 2
answered on 19 Jan 2011, 08:25 PM
um if you want to print - why not use... Telerik Reports?
reuse the dataset you bind to the grid
reuse the dataset you bind to the grid
0
shahid Aleem
Top achievements
Rank 1
answered on 20 Jan 2011, 09:22 AM
But i want to print the rad grid not the rad reports.
0
shahid Aleem
Top achievements
Rank 1
answered on 23 Jan 2011, 12:48 PM
there is no solution for this?
0
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
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.
0
shahid Aleem
Top achievements
Rank 1
answered on 25 Jan 2011, 03:23 PM
thanks a lot mira, this is what i am looking for.
Thanks again.
Thanks again.
0
daniel
Top achievements
Rank 1
answered on 09 Aug 2011, 03:24 PM
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.
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.
0
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
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.
0
stevied
Top achievements
Rank 2
answered on 17 Feb 2012, 04:58 PM
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
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
0
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:
Regards,
Daniel
the Telerik team
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.
0
Jorge
Top achievements
Rank 1
answered on 13 Feb 2014, 01:33 AM
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.
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.
0
Princy
Top achievements
Rank 2
answered on 13 Feb 2014, 05:12 AM
0
Jorge
Top achievements
Rank 1
answered on 13 Feb 2014, 08:17 PM
Thanks, Princy ... nice and simple!
0
Jorge
Top achievements
Rank 1
answered on 14 Feb 2014, 02:42 AM
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?
0
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
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.
0
Jorge
Top achievements
Rank 1
answered on 19 Feb 2014, 05:24 PM
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:
and in the markup you would need the following client side code:
Thanks for your help and hope this helps some one else out.
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.
0
Asutosh
Top achievements
Rank 1
answered on 15 Jul 2014, 05:33 AM
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.
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.
0
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
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.