Hi,
I have a asp.net page( .aspx) with user control( .ascx). That user control has a RADGrid with several records with paging turned on.
When We want to print, we would like to print all rows( not just rows of current page showing in the grid).
Currently, when we print, it is printing only the rows from page that is being shown on the grid on the screen.
To solve the problem, we wanted to hookup onBeforePrint and set the page size to max number of rows and revertback during onafterprint event
. For that we have the following client-side javascript function. But the effect on RADGrid is not happening until after we get
the print dialog and click on the print dialog. We would like to know how to make the RADGrid display all rows before
the print dialog so that print process would pick up the grid with all rows.
We are wondering how we can do this without going to server and disable the paging through Ajax.
<script type="text/javascript">
var pageSize;
var PageCount;
function disableGridPaging()
{
var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
pageSize = grid.MasterTableView.PageSize;
PageCount = grid.MasterTableView.PageCount;
grid.MasterTableView.beginUpdate();
grid.MasterTableView.set_pageSize(grid.MasterTableView.PageSize * grid.MasterTableView.PageCount);
grid.MasterTableView.endUpdate();
}
function revertBackGridPaging()
{
var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
grid.MasterTableView.beginUpdate();
grid.MasterTableView.set_pageSize(pageSize);
grid.MasterTableView.endUpdate();
}
window.onbeforeprint = disableGridPaging
window.onafterprint = revertBackGridPaging
</script>
thanks,
Srini
7 Answers, 1 is accepted
We also tried the server AJAX event approach that was suggested in another post.
On the client we have the following:
Javascript:
-----------
<script type="text/javascript" language="javascript">
function disableGridPaging()
{
var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
grid.get_masterTableView().fireCommand("DisablePaging", "");
}
function revertBackGridPaging()
{
var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
grid.get_masterTableView().fireCommand("EnablePaging", "");
}
window.onbeforeprint=disableGridPaging
window.onafterprint = revertBackGridPaging
</script>
GRID:
-----
<ClientNet:ClientNetRadGrid ID="RadGrid_ContactDetails" runat="server" EnableMouseOver="false"
AutoGenerateColumns="false" AllowMultiRowSelection="false" EnableSelectColumn="false"
DefaultColumnWidth="78" AllowPaging="false" Width="100%" Height="200px" BorderWidth="0px"
EnableAJAXLoadingTemplate="True" EnableAJAX="True" PagerStyle-Mode="NextPrevNumericAndAdvanced"
onitemcommand="RadGrid_ContactDetails_ItemCommand"
CommandItemDisplay="Top" ExcludedFormattingColumn="ContactID">
Server :
--------
protected void RadGrid_ContactDetails_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "DisablePaging")
{
RadGrid_ContactDetails.AllowPaging = false;
RadGrid_ContactDetails.Rebind();
}
else if (e.CommandName == "EnablePaging")
{
RadGrid_ContactDetails.AllowPaging = true;
RadGrid_ContactDetails.Rebind();
}
}
This approach also did not work with print/print preview. The grid is expanding only after the print event.
Wondering how to make grid expand and show all the rows before print process..
Unfortunately, this is not possible. Please refer to the following page for alternative solutions (exporting or disabling Paging with AJAX):
http://www.telerik.com/community/forums/aspnet/grid/72051-radgrid-print.aspx
All the best,
Dimo
the Telerik team
The link is not working.
Regards,
Vijay
Thank you for reporting this!
We have found the problem and you should be able to access the link now.
Sorry for the inconvenience!
FilipS
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.
I'm using radgrid.
Its working fine.
I'm able to print the radgrid.
But while printing I'm disabling the paging and scroll bar and showing the headers.
But these changes are visible to user at front end and there will be distractions till closing the print window.
I'm calling serversice ItemCreated function from client side to disable paging etc...
radGrid.get_masterTableView().fireCommand("EnablePaging", "");
javascript::
'function PrintRadGrid(radGridId, radGridId2) {
var radGrid = $find(radGridId);
var radgrid2=$find(radGridId2);
var previewWnd = window.open('about:blank', '', '', false);
var sh = '<%# ClientScript.GetWebResourceUrl(endPntGrd.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",endPntGrd.Skin)) %>';
var sh1 = '<%# ClientScript.GetWebResourceUrl(dispatcherGrd.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",dispatcherGrd.Skin)) %>';
var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
var styleStr= styleStr+"<html><head><link href = '" + sh1 + "' rel='stylesheet' type='text/css'></link></head>";
var htmlcontent = styleStr + "<body>" + radgrid2.get_element().outerHTML;
var htmlcontent = htmlcontent+"</br>" + styleStr + radGrid.get_element().outerHTML + "</body></html>"; ;
previewWnd.document.open();
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
previewWnd.close();
radGrid.get_masterTableView().fireCommand("EnablePaging", "");
}'
server side::
'protected void endPntGrd_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "EnablePaging")
{
endPntGrd.MasterTableView.ShowHeader = false;
endPntGrd.MasterTableView.GetColumn("chartcolumn").Display = true;
endPntGrd.ClientSettings.Scrolling.AllowScroll = true;
endPntGrd.Rebind();
dispatcherGrd.ClientSettings.Scrolling.AllowScroll = true;
dispatcherGrd.MasterTableView.GetColumn("chartcolumn").Display = true;
dispatcherGrd.MasterTableView.ShowHeader = false;
dispatcherGrd.Rebind();
}
}'
Please can any one help me how to avoid this problem. Really its urgent for me.
Please help me
Hi all,
I have a paged RadGrid with a print function (which is in the RadGrid by default).. it is not printing the generated report in google chrome but its working fine in all the browser , Can anybody Help to solve this problem.
Thank you in advance!
Please note that RadGrid is a complex script control and printing it on a single-click is not fully supported, nor tested. Nevertheless, I am attaching a sample web site to demonstrate how you can print all of the items using an open-in-window approach.
Alternatively, you can try a server-side approach:
bool
isPrinting =
false
;
protected
void
Page_Init(
object
sender, EventArgs e)
{
if
(Session[
"RadGridOutput"
] !=
null
)
{
var output = Session[
"RadGridOutput"
];
// execute custom logic
Session[
"RadGridOutput"
] =
null
;
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
isPrinting =
true
;
RadGrid1.AllowPaging =
false
;
RadGrid1.AllowFilteringByColumn =
false
;
RadGrid1.AllowSorting =
false
;
RadGrid1.Rebind();
RemoveWebControls(RadGrid1);
}
private
void
RemoveWebControls(Control ctrl)
{
var q =
new
Stack<Control>(ctrl.Controls.OfType<Control>());
while
(q.Count > 0)
{
Control control = q.Pop();
if
(control
is
IButtonControl || control
is
ICheckBoxControl || control
is
ITextControl)
ctrl.Controls.Remove(control);
if
(control.HasControls())
RemoveWebControls(control);
}
}
protected
override
void
Render(HtmlTextWriter writer)
{
if
(isPrinting)
{
StringBuilder sb =
new
StringBuilder();
StringWriter strWriter =
new
StringWriter(sb);
HtmlTextWriter newWriter =
new
HtmlTextWriter(strWriter);
RadGrid1.RenderControl(newWriter);
Session[
"RadGridOutput"
] = sb.ToString();
Response.Redirect(Request.Url.ToString());
}
base
.Render(writer);
}
public
override
void
VerifyRenderingInServerForm(Control control)
{
if
(!isPrinting)
base
.VerifyRenderingInServerForm(control);
}
Hope this helps.
Regards,
Eyup
the Telerik team