Hello,
I want to print grid content. I refer http://www.telerik.com/support/code-library/print-radgrid-contents this link.
referring this link print operation perform perfectly but I want to remove some attributes of grid like "allowscrolling,usestaticheader etc" at the time of print grid and after print grid that property again bind to grid.
I am trying this two ways
1.st_approch
On Code Behind
.aspx page
2.nd_approch
.aspx
and the above print code call on button onclientclick event
above both ways not working to achieve the task.
So please tell me how achieve this task.
I want to print grid content. I refer http://www.telerik.com/support/code-library/print-radgrid-contents this link.
referring this link print operation perform perfectly but I want to remove some attributes of grid like "allowscrolling,usestaticheader etc" at the time of print grid and after print grid that property again bind to grid.
I am trying this two ways
1.st_approch
On Code Behind
protected void Page_Load(object sender, EventArgs e)
{
radgrid.ClientSettings.Scrolling.UseStaticHeaders = true;
radgrid.ClientSettings.Scrolling.AllowScroll = true;
radgrid.ClientSettings.Scrolling.SaveScrollPosition = true;
}
protected void btn_print_Click(object sender, EventArgs e)
{
radgrid.ClientSettings.Scrolling.UseStaticHeaders = false;
radgrid.ClientSettings.Scrolling.AllowScroll = false;
radgrid.ClientSettings.Scrolling.SaveScrollPosition = false;
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "function pageLoad(){PrintRadGrid();}", true);
}
function PrintRadGrid() {
$find("<%=radgrid.ClientID %>").get_masterTableView().hideFilterItem();
var previewWnd = window.open('about:blank', '', '', false);
var sh = '<%= ClientScript.GetWebResourceUrl(radgrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radgrid.Skin)) %>';
var styleStr = "<
html
><
head
><
link
href
=
'" + sh + "'
rel
=
'stylesheet'
type
=
'text/css'
></
link
></
head
>";
var htmlcontent = styleStr + "<
body
>" + $find('<%= radgrid.ClientID %>').get_element().outerHTML + "</
body
></
html
>";
previewWnd.document.open();
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
if (!$telerik.isChrome) {
previewWnd.close();
}
$find("<%=radgrid.ClientID %>").get_masterTableView().showFilterItem();
}
2.nd_approch
.aspx
function PrintRadGrid() {
$find("<%=radgrid.ClientID %>").get_masterTableView().hideFilterItem();
var radGrid = $find("<%= radgrid.ClientID %>");
radGrid.ClientSettings.Scrolling.AllowScroll = false;
radGrid.ClientSettings.Scrolling.UseStaticHeaders = false ;
radGrid.ClientSettings.Scrolling.SaveScrollPosition=false;
var previewWnd = window.open('about:blank', '', '', false);
var sh = '<%= ClientScript.GetWebResourceUrl(radgrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radgrid.Skin)) %>';
var styleStr = "<
html
><
head
><
link
href
=
'" + sh + "'
rel
=
'stylesheet'
type
=
'text/css'
></
link
></
head
>";
var htmlcontent = styleStr + "<
body
>" + $find('<%= radgrid.ClientID %>').get_element().outerHTML + "</
body
></
html
>";
previewWnd.document.open();
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
if (!$telerik.isChrome) {
previewWnd.close();
}
$find("<%=radgrid.ClientID %>").get_masterTableView().showFilterItem();
radGrid.ClientSettings.Scrolling.AllowScroll = true;
radGrid.ClientSettings.Scrolling.UseStaticHeaders = true;
radGrid.ClientSettings.Scrolling.SaveScrollPosition = true;
}
above both ways not working to achieve the task.
So please tell me how achieve this task.
9 Answers, 1 is accepted
0
Hi Ganesh,
Actually by following the first approach you should be able to make things work. However in order to ensure that the changes in the grid structure will be applied correctly you should call .Rebind() in the btn_print_click event handler.
In attachments you can find a sample website which follows the scenario and seems to behave as expected on my end. The example should help you in modifying the real code logic accordingly.
Regards,
Angel Petrov
Telerik
Actually by following the first approach you should be able to make things work. However in order to ensure that the changes in the grid structure will be applied correctly you should call .Rebind() in the btn_print_click event handler.
In attachments you can find a sample website which follows the scenario and seems to behave as expected on my end. The example should help you in modifying the real code logic accordingly.
Regards,
Angel Petrov
Telerik
DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.
0

Testing
Top achievements
Rank 1
answered on 20 Mar 2014, 04:42 AM
Hi,
thanks for your response, I refer same example.
I want to to disable grid property like Scrolling,Static Header,Grouping etc at the time of print button click after print complete again that property bind to grid.
Above example remove property of grid at time of print but not rebind after print.
how perform this task?
thanks for your response, I refer same example.
I want to to disable grid property like Scrolling,Static Header,Grouping etc at the time of print button click after print complete again that property bind to grid.
Above example remove property of grid at time of print but not rebind after print.
how perform this task?
0
Hello Ganesh,
I am not quite sure that I completely understand the requirement but if I am correct you want to disable the scrolling, static headers and etc only for the printed grid. This can be achieved by firing a command which to restore the grid settings after it is already printed. In attachments you can find the modified version of the sample which integrates this approach.
Regards,
Angel Petrov
Telerik
I am not quite sure that I completely understand the requirement but if I am correct you want to disable the scrolling, static headers and etc only for the printed grid. This can be achieved by firing a command which to restore the grid settings after it is already printed. In attachments you can find the modified version of the sample which integrates this approach.
Regards,
Angel Petrov
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
0

Testing
Top achievements
Rank 1
answered on 08 Apr 2014, 06:32 AM
Hello Angel,
It work perfectly outside the update panel(asp control).. but when I place it into update panel then its not working.
In my application I place update panel in master page and when I refer above example and try to implement in my application the Itemcommand event not fire after print. ie when client side execute print code its not calling server side again.
how can I use it in update panel.
thank you.
It work perfectly outside the update panel(asp control).. but when I place it into update panel then its not working.
In my application I place update panel in master page and when I refer above example and try to implement in my application the Itemcommand event not fire after print. ie when client side execute print code its not calling server side again.
how can I use it in update panel.
thank you.
0
Hi Ganesh,
I am not sure what exactly is causing this problem but probably it is due to a JavaScript error. Could you ensure that such is not present on the page? Additionally please share with us the code of the page so we could examine the setup.
Regards,
Angel Petrov
Telerik
I am not sure what exactly is causing this problem but probably it is due to a JavaScript error. Could you ensure that such is not present on the page? Additionally please share with us the code of the page so we could examine the setup.
Regards,
Angel Petrov
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.
0

Testing
Top achievements
Rank 1
answered on 11 Apr 2014, 12:11 PM
Hello Angel,
I refer same example that you had previously send. Just edit that example and place rad-grid within update panel and its not working. If I remove update panel then it works fine.
Please check code..
.aspx file
.Cs File
I refer same example that you had previously send. Just edit that example and place rad-grid within update panel and its not working. If I remove update panel then it works fine.
Please check code..
.aspx file
<
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
>
<
asp:UpdatePanel
ID
=
"update_Return_chk"
runat
=
"server"
>
<
ContentTemplate
>
<
telerik:RadGrid
ID
=
"radGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
Style
=
"margin: 20px;"
AllowPaging
=
"True"
OnItemCommand
=
"radGrid1_ItemCommand"
AllowSorting
=
"True"
PageSize
=
"50"
AllowFilteringByColumn
=
"True"
>
<
MasterTableView
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"False"
DataKeyNames
=
"Agent_Information_Id"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Agent_Information_Id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Agent_Information_Id column"
HeaderText
=
"Agent_Information_Id"
ReadOnly
=
"True"
SortExpression
=
"Agent_Information_Id"
UniqueName
=
"Agent_Information_Id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"First_Name"
FilterControlAltText
=
"Filter First_Name column"
HeaderText
=
"First_Name"
SortExpression
=
"First_Name"
UniqueName
=
"First_Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Middle_Name"
FilterControlAltText
=
"Filter Middle_Name column"
HeaderText
=
"Middle_Name"
SortExpression
=
"Middle_Name"
UniqueName
=
"Middle_Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Last_Name"
FilterControlAltText
=
"Filter Last_Name column"
HeaderText
=
"Last_Name"
SortExpression
=
"Last_Name"
UniqueName
=
"Last_Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Middle_Name_Arabic"
FilterControlAltText
=
"Filter Middle_Name_Arabic column"
HeaderText
=
"Middle_Name_Arabic"
SortExpression
=
"Middle_Name_Arabic"
UniqueName
=
"Middle_Name_Arabic"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"First_Name_Arabic"
FilterControlAltText
=
"Filter First_Name_Arabic column"
HeaderText
=
"First_Name_Arabic"
SortExpression
=
"First_Name_Arabic"
UniqueName
=
"First_Name_Arabic"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Last_Name_Arabic"
FilterControlAltText
=
"Filter Last_Name_Arabic column"
HeaderText
=
"Last_Name_Arabic"
SortExpression
=
"Last_Name_Arabic"
UniqueName
=
"Last_Name_Arabic"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Contact_Address"
FilterControlAltText
=
"Filter Contact_Address column"
HeaderText
=
"Contact_Address"
SortExpression
=
"Contact_Address"
UniqueName
=
"Contact_Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Contact_Number"
FilterControlAltText
=
"Filter Contact_Number column"
HeaderText
=
"Contact_Number"
SortExpression
=
"Contact_Number"
UniqueName
=
"Contact_Number"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Fax_Number"
FilterControlAltText
=
"Filter Fax_Number column"
HeaderText
=
"Fax_Number"
SortExpression
=
"Fax_Number"
UniqueName
=
"Fax_Number"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"PoBox_Number"
FilterControlAltText
=
"Filter PoBox_Number column"
HeaderText
=
"PoBox_Number"
SortExpression
=
"PoBox_Number"
UniqueName
=
"PoBox_Number"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Contact_Email_Id"
FilterControlAltText
=
"Filter Contact_Email_Id column"
HeaderText
=
"Contact_Email_Id"
SortExpression
=
"Contact_Email_Id"
UniqueName
=
"Contact_Email_Id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Country_Id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Country_Id column"
HeaderText
=
"Country_Id"
SortExpression
=
"Country_Id"
UniqueName
=
"Country_Id"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
ContentTemplate
></
asp:UpdatePanel
>
</
div
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:PropMgmtConnectionString %>"
SelectCommand="SELECT [Agent_Information_Id], [First_Name], [Middle_Name], [Last_Name], [Middle_Name_Arabic], [First_Name_Arabic], [Last_Name_Arabic], [Contact_Address], [Contact_Number], [Fax_Number], [PoBox_Number], [Contact_Email_Id], [Country_Id] FROM [Agent_Information]">
</
asp:SqlDataSource
>
</
form
>
</
body
>
</
html
>
protected
void
Page_Load(
object
sender, EventArgs e)
{
radGrid1.ClientSettings.Scrolling.UseStaticHeaders =
true
;
radGrid1.ClientSettings.Scrolling.AllowScroll =
true
;
radGrid1.ClientSettings.Scrolling.SaveScrollPosition =
true
;
}
protected
void
Unnamed_Click(
object
sender, EventArgs e)
{
radGrid1.ClientSettings.Scrolling.UseStaticHeaders =
false
;
radGrid1.ClientSettings.Scrolling.AllowScroll =
false
;
radGrid1.ClientSettings.Scrolling.SaveScrollPosition =
false
;
radGrid1.Rebind();
ScriptManager.RegisterStartupScript(
this
,
typeof
(Page),
"myscript"
,
"function pageLoad(){PrintRadGrid(); $find('radGrid1').get_masterTableView().fireCommand('RetainPrevState','') }"
,
true
);
}
protected
void
radGrid1_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName ==
"RetainPrevState"
)
{
radGrid1.ClientSettings.Scrolling.UseStaticHeaders =
true
;
radGrid1.ClientSettings.Scrolling.AllowScroll =
true
;
radGrid1.ClientSettings.Scrolling.SaveScrollPosition =
true
;
radGrid1.Rebind();
}
}
0

Testing
Top achievements
Rank 1
answered on 16 Apr 2014, 05:58 AM
hello,
I ask question, is their any solution for that??
I ask question, is their any solution for that??
0
Accepted
Hello Ganesh,
After isolating the problem in a local sample I noticed that PrintRadGrid was called numerous times. This was caused by the fact that the function is called in the pageLoad script and that the script itself invokes a round-trip to the server. In order to make things work you can try integrating the solution provided in the attached website.
Regards,
Angel Petrov
Telerik
After isolating the problem in a local sample I noticed that PrintRadGrid was called numerous times. This was caused by the fact that the function is called in the pageLoad script and that the script itself invokes a round-trip to the server. In order to make things work you can try integrating the solution provided in the attached website.
Regards,
Angel Petrov
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.
0

Testing
Top achievements
Rank 1
answered on 18 Apr 2014, 11:04 AM
Hi Angel,
thank you :) , its working now.
thank you :) , its working now.