I am trying to export a radgird to word. But it is not showing me it in proper way.
Please find attached images of how the grid looks and how it gets exported to word.
How to export it as it is on the page, without the controls like Radio buttons and text boxes?
19 Answers, 1 is accepted
To achieve the desired result, you need to set the ExportOnlyData property to True which is part from the export settings of RadGrid. Thus you will get only data from grid without the controls. More information about this property and some others you could find here.
Best wishes,
Andrey
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Thanks for the reply.
I tried it out, but it does not help me. Even I tried by exporting the grid to PDF, but it prints nothing.
My radgrid data are same as i posted as image earlier.
Could it be a issue with templates?
As I don't have the typical grid view format of columns. Instead, I have a single itemtemplate and in that there is one table which shows all the data.
To export grid to PDF, I have taken one button and on click of that, have written the flowing code:
dtBook.ExportSettings.ExportOnlyData = true;
dtBook.MasterTableView.ExportToPdf();
And it looks like the image attached with this post.
What's wrong with it? Can you please try to solve this out ASAP?

Thanks for the reply.
I tried it out, but it does not help me. Even I tried by exporting the grid to PDF, but it prints nothing.
My radgrid data are same as i posted as image earlier.
Could it be a issue with templates?
As I don't have the typical grid view format of columns. Instead, I have a single itemtemplate and in that there is one table which shows all the data.
To export grid to PDF, I have taken one button and on click of that, have written the flowing code:
dtBook.ExportSettings.ExportOnlyData = true;
dtBook.MasterTableView.ExportToPdf();
And it looks like the image attached with this post.
What's wrong with it? Can you please try to solve this out ASAP?

Try calling the Rebind() method after exporting. Also check the following help documentation which explains exporting to pdf.
PDF export.
Thanks,
Princy

I tried your solution but no help.
Gridview is like this:
<
telerik:RadGrid
ID
=
"dtBook"
AllowPaging
=
"True"
runat
=
"server"
PageSize
=
"10"
ShowHeader
=
"false"
OnItemDataBound
=
"dtBook_ItemDataBound"
Width
=
"100%"
Height
=
"100%"
OnPageIndexChanged
=
"dtBook_PageIndexChanged"
>
<
PagerStyle
Mode
=
"NumericPages"
/>
<
MasterTableView
TableLayout
=
"Fixed"
DataKeyNames
=
"BookID,writerid,categoryname,type,playerid,Bookdate,attachment,playeridFilter,ShareTo"
>
<
ItemTemplate
>
<
table
border
=
"2"
>
..........All the rows here.............
</
table
>
</
ItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
btnWord_Click(
object
sender, System.EventArgs e)
{
isExport =
true
;
ConfigureExport();
dtBook.ExportSettings.ExportOnlyData =
true
;
foreach
(GridDataItem item
in
dtBook.Items)
item.Style[
"background-color"
] =
"#888888"
;
dtBook.MasterTableView.ExportToPdf();
dtBook.MasterTableView.Rebind();
}
But it just shows the datakeynames in the PDF.. Not getting what's wrong?????

Replace this line with below code : dtBook.MasterTableView.Rebind();
dtBook
.DataSource = ""; // Assign your datasource here;dtBook
.DataBind();Let me know if any concern.
Thanks,
Jayesh Goyani

Thanks for the reply.
I tried by your way, but it does not export anything, the word file is blank. I tried by binding the grid with data before it export it. But then also it exports null.
What could be the issue?

There is not any issue in your code.
please attach your code or project so we can find the actual problem.
Thanks,
Jayesh Goyani

You can check the page live at:
http://121.247.170.47/GPWeb/coach/testpage.aspx
UserName: t
Password: t
There is one "Print" link on page in green, on click of that it should export the grid to word by "
btnWord_Click
".But it exports it blank.
I need to print all the data without the images and textboxes. "Attachments" and "Comment" division also contains some data, it should also be exported.
ASPX code:
<
tr
>
<
td
colspan
=
"2"
>
<
center
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
</
center
>
<
telerik:RadAjaxPanel
ID
=
"radPanel1"
runat
=
"server"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
ClientEvents-OnRequestStart
=
"OnRequestStart"
>
<
telerik:RadGrid
ID
=
"dtBook"
AllowPaging
=
"True"
runat
=
"server"
PageSize
=
"10"
ShowHeader
=
"false"
OnItemDataBound
=
"dtBook_ItemDataBound"
Width
=
"100%"
Height
=
"100%"
>
<
PagerStyle
Mode
=
"NumericPages"
/>
<
MasterTableView
TableLayout
=
"Fixed"
DataKeyNames
=
"BookID,writerid,categoryname,type,playerid,Bookdate,attachment,playeridFilter,ShareTo,subjectId,ExerciseVideos,url,facebook,twitter,tfUserID"
>
<
ItemTemplate
>
<
table
>
<
tr
>
<
td
class
=
"gridtableborder"
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
id
=
"trBookID"
runat
=
"server"
>
<
td
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
>
<
td
height
=
"30"
>
<
table
>
<
tr
>
<
td
valign
=
"top"
>
<
table
width
=
"100%"
>
<
tr
>
<
td
>
<
table
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
>
<
td
align
=
"left"
valign
=
"top"
style
=
"text-align: center"
>
<
asp:Image
runat
=
"server"
ID
=
"imgUserImage"
BorderWidth
=
"0px"
ImageAlign
=
"Middle"
/>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
valign
=
"top"
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
>
<
td
align
=
"left"
valign
=
"top"
width
=
"23px"
>
<
img
src
=
"../forum/forumimages2/bshadow-gray-left.gif"
alt
=
""
width
=
"23px"
height
=
"5"
/>
</
td
>
<
td
align
=
"right"
valign
=
"top"
width
=
"23px"
>
<
img
src
=
"../forum/forumimages2/bshadow-gray-right.gif"
alt
=
""
width
=
"23px"
height
=
"5"
/>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
td
>
<
td
class
=
"commentstext"
>
Logbook dated
<
asp:Label
ID
=
"lblDate"
runat
=
"server"
></
asp:Label
>
for
<%# Eval("Name") %>
by
<
asp:Label
ID
=
"lblWriter"
runat
=
"server"
></
asp:Label
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"5"
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"1"
cellpadding
=
"5"
>
<
tr
>
<
td
width
=
"80"
align
=
"right"
>
<
strong
>Category:</
strong
>
</
td
>
<
td
>
Golf Training
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"right"
valign
=
"top"
>
<
strong
>Notes:</
strong
>
</
td
>
<
td
>
<
div
id
=
"dvText"
runat
=
"server"
>
<%# Eval("Booktext") %>
</
div
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"10"
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
class
=
"gridtableborder"
style
=
"padding: 0px;"
>
<
tr
>
<
td
valign
=
"middle"
>
<
div
class
=
"eg-bar"
id
=
"div11"
runat
=
"server"
>
<
span
id
=
"faq1-title"
class
=
"iconspan"
>
<
img
class
=
"attachmentImage"
src
=
"../Images/Logbook_Images/down-arrow.png"
/>
</
span
>Attachments:
<
asp:Label
ID
=
"lblTotalAttachments"
class
=
"count"
runat
=
"server"
ForeColor
=
"Green"
></
asp:Label
>
<
asp:ImageButton
ID
=
"imgAdd"
runat
=
"server"
ImageUrl
=
"../Forum/ForumImages2/icon-add.png"
/>
<
asp:ImageButton
ID
=
"ibtnLink"
runat
=
"server"
ImageUrl
=
"~/Images/yt.png"
/>
</
div
>
<
div
id
=
"faq1"
class
=
"icongroup1"
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
>
<
td
>
<
asp:Label
ID
=
"lblAttachmentMsg"
runat
=
"server"
Text
=
"No attachments available, you can add by using the '+' icon above"
ForeColor
=
"Red"
Visible
=
"false"
></
asp:Label
>
<
div
id
=
"divAttachments"
runat
=
"server"
>
</
div
>
<%--YouTube video links will be shown in this div--%>
<
div
id
=
"divYouTube"
runat
=
"server"
class
=
"divYouTubeClass"
>
</
div
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"10"
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
class
=
"gridtableborder"
style
=
"padding: 0px;"
>
<
tr
>
<
td
>
<
div
class
=
"eg-bar"
>
<
span
id
=
"faq2-title"
class
=
"iconspan"
>
<
img
src
=
"../Images/Logbook_Images/down-arrow.png"
class
=
"attachmentImage"
/></
span
>Comments:
<
asp:Label
ID
=
"lblTotalComments"
runat
=
"server"
ForeColor
=
"Green"
></
asp:Label
></
div
>
<
div
id
=
"faq2"
class
=
"icongroup1"
runat
=
"server"
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
tr
>
<
td
>
<
div
id
=
"divComments"
class
=
"Comments"
runat
=
"server"
style="background-color: #EDEFF4;
border: 1px; border-style: solid; border-color: #dbdbdb; padding-left: 3px;">
<
asp:Label
ID
=
"lblCommentMessage"
runat
=
"server"
Text
=
"No comments entered yet."
ForeColor
=
"Red"
Visible
=
"false"
class
=
"CommentMessage"
></
asp:Label
>
<
telerik:RadGrid
ID
=
"radComments"
AllowPaging
=
"True"
runat
=
"server"
PageSize
=
"15"
Skin
=
""
GridLines
=
"None"
BorderStyle
=
"None"
BorderColor
=
"Transparent"
ShowHeader
=
"false"
OnItemCommand
=
"radComments_ItemCommand"
OnItemDataBound
=
"radComments_ItemDataBound"
Width
=
"97%"
EnableTheming
=
"false"
Style
=
"padding-left: 16px;"
>
<
PagerStyle
Mode
=
"NumericPages"
/>
<
MasterTableView
TableLayout
=
"Fixed"
Width
=
"100%"
Height
=
"100%"
BorderStyle
=
"None"
DataKeyNames
=
"BookID,commentid,CommentAttachment,userid,Commenttype"
>
<
ItemTemplate
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"1"
cellpadding
=
"1"
>
<
tr
>
<
td
valign
=
"top"
align
=
"left"
style
=
"text-align: center; width: 5%;"
class
=
"box-border"
>
<
asp:Image
ImageAlign
=
"AbsMiddle"
ID
=
"imgWriterImage"
runat
=
"server"
/>
</
td
>
<
td
width
=
"20%"
align
=
"left"
>
<
strong
>
<%# Eval("UserName") + ":" %></
strong
>
</
td
>
<
td
class
=
"altbg"
width
=
"45%"
align
=
"left"
>
<%# Eval("Commenttext") %>
</
td
>
<
td
width
=
"20%"
align
=
"left"
>
<
asp:Label
ID
=
"lblType"
runat
=
"server"
Text='<%# Eval("Commenttype") %>'></
asp:Label
>
</
td
>
<
td
align
=
"center"
width
=
"20%"
>
<
asp:HiddenField
ID
=
"hdnCommentID"
runat
=
"server"
Value='<%# Eval("commentid") %>' />
<
asp:HiddenField
ID
=
"hdnBookID"
runat
=
"server"
Value='<%# Eval("bookid") %>' />
<
asp:ImageButton
ID
=
"btnImgEdit"
runat
=
"server"
ImageUrl
=
"~/Forum/ForumImages2/edit.gif"
OnClientClick
=
"Edit(this);return false;"
ToolTip
=
"Edit"
/>
<
asp:ImageButton
ID
=
"btnImgDelete"
runat
=
"server"
ImageUrl
=
"~/Forum/ForumImages2/delete.gif"
class
=
"DelComment"
ToolTip
=
"Delete"
/>
</
td
>
</
tr
>
</
table
>
</
ItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"10"
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"30"
class
=
"commentstext"
>
Write Comments For:
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"writecommentpad"
>
<
asp:RadioButton
ID
=
"rdoPublic"
runat
=
"server"
AutoPostBack
=
"false"
Checked
=
"true"
CssClass
=
"PageLabel"
GroupName
=
"GrpCommentType"
Text
=
"Player & Coaches"
/>
<
asp:RadioButton
ID
=
"rdocoaches"
runat
=
"server"
AutoPostBack
=
"false"
CssClass
=
"PageLabel"
GroupName
=
"GrpCommentType"
Text
=
"Coaches"
/>
<
asp:RadioButton
ID
=
"rdoPrivate"
runat
=
"server"
AutoPostBack
=
"false"
CssClass
=
"PageLabel"
GroupName
=
"GrpCommentType"
Text
=
"Me (Private)"
/>
<
br
/>
<
asp:Panel
ID
=
"pnlComment"
runat
=
"server"
Style
=
"padding-left: 20px;"
>
<
asp:HiddenField
ID
=
"hdnCommentBookID"
runat
=
"server"
Value='<%# Eval("BookID")%> ' />
<
asp:TextBox
ID
=
"txtComment"
class
=
"water"
runat
=
"server"
Width
=
"85%"
BorderStyle
=
"Solid"
BorderWidth
=
"1px"
ToolTip
=
"Write a comment..."
BorderColor
=
"#dbdbdb"
Text
=
"Write a comment..."
ValidationGroup='<%# DataBinder.Eval(Container,"ItemIndex") %>'></
asp:TextBox
><
br
/>
</
asp:Panel
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
>
<
td
height
=
"30"
align
=
"right"
valign
=
"bottom"
id
=
"trComment"
runat
=
"server"
>
<
table
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
style
=
"margin-right: 13px"
id
=
"tblFB"
runat
=
"server"
>
<
tr
>
<
td
width
=
"100"
align
=
"right"
valign
=
"bottom"
>
<
asp:HiddenField
ID
=
"hdnBookID"
runat
=
"server"
Value='<%# Eval("BookID") %>' />
<
asp:ImageButton
ID
=
"imgLike"
class
=
"FBLike"
runat
=
"server"
ImageUrl
=
"../Images/Logbook_Images/login-Thick.png"
ToolTip="<%$ Resources:WebResource , Book_Like %>" />
<%--<
asp:LinkButton
ID
=
"lnkUnlike"
runat
=
"server"
Text
=
"Unlike"
Visible
=
"false"
/>--%>
<
asp:ImageButton
ID
=
"lnkUnlike"
class
=
"FBLike"
runat
=
"server"
ImageUrl
=
"../Images/Logbook_Images/sad-smiley.png"
ToolTip
=
"Unlike"
/>
<%--'<%#String.Format("UnLike(""{0}"");return false;",Eval("BookID"))%>'--%>
<%--'<%# Eval("BookID", "UnLike({0});return false;") %>' --%>
</
td
>
<
td
id
=
"tdLike"
runat
=
"server"
style
=
"display: none;"
valign
=
"bottom"
>
<
asp:Label
ID
=
"lblLike"
runat
=
"server"
ForeColor
=
"Green"
Visible
=
"false"
> </
asp:Label
>
<
a
class
=
"LikeUsers"
id
=
"lnkLike"
runat
=
"server"
></
a
>
</
td
>
<
td
width
=
"30"
align
=
"right"
valign
=
"middle"
>
<%--<
a
href
=
"#"
>
<
img
src
=
"../Images/Logbook_Images/facebook_icon.png"
alt
=
"Facebook"
title
=
"Facebook"
/></
a
>--%>
<
asp:ImageButton
ID
=
"ibtnFaceBook"
runat
=
"server"
ImageUrl
=
"~/Images/facebook_16.png"
/>
</
td
>
<
td
width
=
"30"
align
=
"right"
valign
=
"middle"
>
<
asp:ImageButton
ID
=
"btnImgEdit"
runat
=
"server"
CommandArgument='<%# Eval("BookID") %>'
ImageUrl="~/Forum/ForumImages2/Edit.gif" ToolTip="<%$ Resources:WebResource , BookRead_Edit %>" />
</
td
>
<
td
width
=
"30"
align
=
"right"
valign
=
"middle"
>
<
asp:ImageButton
ID
=
"btnImgDelete"
runat
=
"server"
CommandArgument='<%# Eval("BookID") %>'
ImageUrl="~/Forum/ForumImages2/delete.gif" ToolTip="<%$ Resources:WebResource , BookRead_Delete %>" />
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
<
br
/>
</
ItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
<%--<
asp:TextBox
ID
=
"txt1"
runat
=
"server"
onkeyup
=
"aa(this);"
></
asp:TextBox
>--%>
<
asp:Button
ID
=
"btnRefreshComments"
runat
=
"server"
Style
=
"display: none;"
/>
<
asp:Button
ID
=
"btnAddEditComments"
runat
=
"server"
Style
=
"display: none;"
/>
</
telerik:RadAjaxPanel
>
</
td
>
</
tr
>
CS code:
private
bool
isExport =
false
;
protected
void
Page_Load(
object
sender, EventArgs e)
{
BindGrid();
}
protected
void
btnWord_Click(
object
sender, System.EventArgs e)
{
isExport =
true
;
dtBook.ExportSettings.ExportOnlyData =
true
;
dtBook.MasterTableView.ExportToWord();
dtBook.DataSource =
""
;
dtBook.DataBind();
}
protected
void
dtBook_GridExporting(
object
source, Telerik.Web.UI.GridExportingArgs e)
{
e.ExportOutput = e.ExportOutput.Replace(
"<br />"
,
""
);
e.ExportOutput = e.ExportOutput.Replace(
"<br />"
,
"
"
);
}
public
void
BindGrid()
{
Book_text objBookText =
new
Book_text();
DataTable dtable =
new
DataTable();
DataTable dtablePaging =
new
DataTable();
DateTime bookDate2 =
default
(DateTime);
objBookText.BookDate = Convert.ToDateTime(
"2011/08/28"
);
bookDate2 = Convert.ToDateTime(
"2011/09/01"
);
objBookText.SubjectID =
""
;
objBookText.WriterID = GolfSession.UserID;
if
(rdoPlayer.Checked)
{
if
(!
string
.IsNullOrEmpty(ddPlayer.SelectedValue.ToString()))
{
objBookText.PlayerID = ddPlayer.SelectedValue.ToString();
}
else
{
objBookText.PlayerID =
""
;
}
}
else
{
objBookText.WriterID =
""
;
//added by mansi shah - 12 Jul 2010
objBookText.PlayerID =
""
;
}
objBookText.WriterID = GolfSession.UserID;
string
strTeamId =
""
;
if
((rdoTeam.Checked))
{
if
((
string
.IsNullOrEmpty(ddTeam.SelectedValue) | ddTeam.SelectedValue ==
"0"
))
{
strTeamId =
""
;
}
else
{
strTeamId = ddTeam.SelectedValue;
}
}
else
{
strTeamId =
""
;
}
if
(rdoPlayer.Checked)
{
dtable = objBookText.SearchCoachLogbookbycoach(bookDate2, GolfSession.Language, GolfSession.UserID, ddPlayer.SelectedValue,
""
, categoryType);
}
else
{
dtable = objBookText.SearchCoachLogbookbycoach(bookDate2, GolfSession.Language, GolfSession.UserID,
""
, strTeamId,
""
);
}
if
(rdoPlayer.Checked)
{
dtable = objBookText.SearchCoachLogbookbycoach(bookDate2, GolfSession.Language, GolfSession.UserID, ddPlayer.SelectedValue,
""
, categoryType);
}
else
{
dtable = objBookText.SearchCoachLogbookbycoach(bookDate2, GolfSession.Language, GolfSession.UserID,
""
, strTeamId, categoryType);
}
dtBook.DataSource = dtable;
dtBook.DataBind();
}
protected
void
dtBook_ItemDataBound(
object
sender, GridItemEventArgs e)
{
Book_Comment objComment =
new
Book_Comment();
DataTable dt =
new
DataTable();
Label lblDate =
default
(Label);
ImageButton imgDelete =
new
ImageButton();
ImageButton imgAdd =
new
ImageButton();
ImageButton ibtnLink =
new
ImageButton();
HtmlGenericControl dvText =
new
HtmlGenericControl(
"div"
);
ImageButton imgEdit =
new
ImageButton();
HtmlAnchor lnkLike =
new
HtmlAnchor();
Label lblLike =
new
Label();
ImageButton lnkUnlike =
new
ImageButton();
System.Web.UI.WebControls.Image imgLike =
new
System.Web.UI.WebControls.Image();
System.Web.UI.WebControls.Image imgLikeUser =
new
System.Web.UI.WebControls.Image();
System.Web.UI.WebControls.Image imgUserImage =
new
System.Web.UI.WebControls.Image();
System.Web.UI.WebControls.Label lblAttachmentMsg =
null
;
if
((e.Item.ItemType == GridItemType.AlternatingItem | e.Item.ItemType == GridItemType.Item))
{
ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"BookID"
].ToString();
string
BookId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"BookID"
].ToString();
dvText = (HtmlGenericControl)e.Item.FindControl(
"dvText"
);
lblDate = (Label)e.Item.FindControl(
"lblDate"
);
TextBox txtComment = (TextBox)e.Item.FindControl(
"txtComment"
);
Button btnComment = (Button)e.Item.FindControl(
"btnComment"
);
lblAttachmentMsg = (Label)e.Item.FindControl(
"lblAttachmentMsg"
);
if
(dvText.InnerHtml.ToLower().Contains(
"font"
))
{
string
str = dvText.InnerHtml;
}
dvText.InnerHtml = dvText.InnerHtml.Replace(
"background-color: #e5e5e5"
,
""
);
dvText.InnerHtml = dvText.InnerHtml.Replace(
"background-color: rgb(229, 229, 229)"
,
""
);
if
(dvText.InnerHtml.ToLower().Contains(
"span"
))
{
ClientScript.RegisterStartupScript(Page.GetType(),
"bb"
,
"<script language=javascript> alert('in');ReplaceSpanTags("
+ dvText.InnerHtml +
");return false;</script>"
);
}
User_data objuser_data =
new
User_data();
DataTable dtWriterName = objuser_data.GetUserNamesByID(strwriterid);
if
(dtWriterName !=
null
&& dtWriterName.Rows.Count >= 1)
{
Label lblWriter = (Label)e.Item.FindControl(
"lblWriter"
);
lblWriter.Text = dtWriterName.Rows[0][0].ToString();
}
Genral objGenral =
new
Genral();
DataTable dtable = objGenral.SelectUserData(strwriterid);
string
photo = Convert.ToString(dtable.Rows[0][
"photo"
]);
try
{
string
strFile = photo.Substring(0, photo.LastIndexOf(
"."
));
string
strExt = photo.Substring(photo.LastIndexOf(
"."
) + 1);
imgUserImage = (System.Web.UI.WebControls.Image)e.Item.FindControl(
"imgUserImage"
);
imgUserImage.ImageUrl =
"imager.aspx?img="
+ strFile +
"&imgExt="
+ strExt +
"&sz=50&image=1"
;
}
catch
{
imgUserImage = (System.Web.UI.WebControls.Image)e.Item.FindControl(
"imgUserImage"
);
imgUserImage.ImageUrl =
"imager.aspx?img=''&imgExt=''&sz=50&image=1"
;
}
string
strExerciseVideos = Convert.ToString(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"ExerciseVideos"
]);
lblDate.Text = dtDate;
#endregion
#region "Comments"
RadGrid radComments = (RadGrid)e.Item.FindControl(
"radComments"
);
Button objButtonRefresh = (Button)e.Item.FindControl(
"btnRefreshComments"
);
HtmlGenericControl divComments = (HtmlGenericControl)e.Item.FindControl(
"divComments"
);
Label lblCommentMessage = (Label)e.Item.FindControl(
"lblCommentMessage"
);
if
(radComments !=
null
)
{
ShowComments(BookId, radComments);
Label lblTotalComments = (Label)e.Item.FindControl(
"lblTotalComments"
);
lblTotalComments.Text =
"("
+ radComments.Items.Count.ToString() +
")"
;
if
(radComments.Items.Count < 1)
lblCommentMessage.Visible =
true
;
else
lblCommentMessage.Visible =
false
;
}
#endregion
}
}
protected
void
radComments_ItemDataBound(
object
sender, GridItemEventArgs e)
{
}
//[System.Web.Services.WebMethod]
public
static
void
ShowComments(
string
bookID, RadGrid radComments)
{
Book_Comment objComment =
new
Book_Comment();
DataTable dt =
new
DataTable();
objComment.BookID = bookID;
objComment.UserID = GolfSession.UserID;
dt = objComment.SelectbyUserId();
DataView dv = dt.DefaultView;
if
(dt.Rows.Count > 0)
{
radComments.DataSource = dt;
radComments.DataBind();
}
else
{
radComments.DataSource =
null
;
radComments.DataBind();
}
// Session["radComments"] = radComments;
}
protected
void
dtBook_ItemCreated(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
((e.Item
is
GridDataItem || e.Item
is
GridHeaderItem) & isExport ==
true
)
{
if
(e.Item
is
GridHeaderItem)
{
e.Item.Visible =
false
;
}
if
(e.Item
is
GridDataItem)
{
e.Item.Style[
"color"
] =
"black"
;
// Default color for dataitem
foreach
(TableCell cell
in
e.Item.Cells)
{
cell.Style[
"font-family"
] =
"Verdana"
;
cell.Style[
"text-align"
] =
"left"
;
cell.Style[
"vertical-align"
] =
"middle"
;
cell.Style[
"font-size"
] =
"10px"
;
}
}
GridDataItem item = e.Item
as
GridDataItem;
}
switch
(e.Item.ItemType)
{
//Mimic RadGrid appearance for the exported PDF file
case
GridItemType.Item:
e.Item.Style[
"background-color"
] =
"#DBDBDB"
;
break
;
case
GridItemType.AlternatingItem:
e.Item.Style[
"background-color"
] =
"#FFFFFF"
;
break
;
case
GridItemType.Header:
e.Item.Style[
"background-color"
] =
"#344040"
;
break
;
case
GridItemType.CommandItem:
e.Item.Style[
"background-color"
] =
"#000000"
;
break
;
}
if
(e.Item
is
GridCommandItem)
{
//needed to span the image over the CommandItem cells
e.Item.PrepareItemStyle();
}
}
protected
void
radComments_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"Update"
)
{
Response.Write(
"update"
);
}
}
Can anybody tell what is the issue?
Straight to the point:
First, note that we recommend using advanced data binding through NeedDataSource event rather than simple data binding through RadGrid.DataBind() method. More about advanced data binding you could read here.
Second, please note that "&" is binary "AND" operation, when comparing values, you should use "&&" which is logical "AND" operation. I am referring to this line of code:
protected
void
dtBook_ItemCreated(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
((e.Item
is
GridDataItem || e.Item
is
GridHeaderItem) & isExport ==
true
)
}
Third, please remove all runat attributes from your HTML table tag, this attribute is causing the blank files after export to word function is performed. This is applicable only when ExportOnlyData is equal to true. If you want to preserve the runat attribute you should set ExportOnlyData property to false.
Fourth, to able successfully to export to PDF, you should use <colgroup> and <col> tags in every definition of a html table, this requirement is described here(section Exporting HTML tables). The number of <col> tags should be equal to the number of columns in your table. Your html table code should be something similar to that:
<ItemTemplate>
<table>
<colgroup>
<col />
</colgroup>
<tr>
<td
class
=
"gridtableborder"
>
<table width=
"100%"
border=
"0"
cellspacing=
"0"
cellpadding=
"0"
>
<colgroup>
<col />
</colgroup>
..................
..................
Regards,
Andrey
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

I have created one sample page, for a alternate to my requirement. But while exporting it shows column name in word. I don't have to show the column names while exporting as my format is different. Also, it does not show the same fonts in word as it is showing on web page. How to show it in same style with height width settings too.?
Here is that sample code:
ASPX:
<asp:Button ID="btnExport" runat="server" Text="Export to word" OnClick="btnExport_Click" />
<
telerik:RadGrid
ID
=
"radPrint"
AllowPaging
=
"True"
runat
=
"server"
PageSize
=
"10"
ShowHeader
=
"false"
Font-Names
=
"verdana"
Font-Size
=
"Smaller"
Width
=
"100%"
Height
=
"100%"
>
<
PagerStyle
Mode
=
"NumericPages"
/>
<
MasterTableView
TableLayout
=
"Fixed"
>
<
ItemTemplate
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
>
<
colgroup
>
<
col
/>
<
col
/>
</
colgroup
>
<
tr
>
<
td
valign
=
"top"
colspan
=
"2"
>
Logbook for
<%# Eval("Name") %>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
width
=
"50px"
>
<
strong
>Category:</
strong
>
</
td
>
<
td
width
=
"700px"
>
Golf Training
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"left"
width
=
"50px"
>
<
strong
>Notes:</
strong
>
</
td
>
<
td
width
=
"600px"
>
<
div
id
=
"dvText"
runat
=
"server"
style
=
"width: 600px"
>
Shot 72 (0) strokes at AIK Golf>9 hole test course>Beginners tee. Brief game statistics: GIR=100%; Putts/GIR=2.000. Processes: Think=4; Play=97. Good: Improve: sdfsfsd How: .
</
div
>
</
td
>
</
tr
>
</
table
>
</
ItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
CS:
DataTable dtTemp =
new
DataTable();
DataColumn dc1 =
new
DataColumn();
dc1.ColumnName =
"name"
;
dtTemp.Columns.Add(dc1);
DataRow dr1 = dtTemp.NewRow();
dr1[0] =
"aaa"
;
dtTemp.Rows.Add(dr1);
DataRow dr2 = dtTemp.NewRow();
dr2[0] =
"bbb"
;
dtTemp.Rows.Add(dr2);
radPrint.DataSource = dtTemp;
radPrint.DataBind();
protected
void
btnExport_Click(
object
sender, EventArgs e)
{
radPrint.ExportSettings.ExportOnlyData =
false
;
radPrint.MasterTableView.ExportToWord();
}

for remove column header
protected
void
radPrint_GridExporting(
object
sender, GridExportingArgs e)
{
e.ExportOutput = e.ExportOutput.Substring(0, e.ExportOutput.IndexOf(
"<thead>"
) + 7) + e.ExportOutput.Substring(e.ExportOutput.IndexOf(
"</thead>"
));
// e.ExportOutput = e.ExportOutput.Replace("<body>", "<body style=\"font:25px tahoma,verdana,sans-serif;>\" ");
}
for set fontsize and fontname
<
ItemTemplate
>
<
table
width
=
"100%"
border
=
"0"
cellspacing
=
"0"
cellpadding
=
"0"
style="font-family: Verdana;
font-size: 15px;">
Thanks,
Jayesh Goyani

It works well. Can you please advice me what to do for the nested grid column headers?

if possible then provide Radgrid's code.(from aspx)
So i can check it from my side and give back to you.
Thanks,
Jayesh Goyani


please set "AutoGenerateColumns="false"" to your RADgrid and let me know it works or not?
Thanks,
Jayesh Goyani


protected
void
radPrint_GridExporting(
object
sender, GridExportingArgs e)
{
e.ExportOutput = RemoveColumnHeader(e.ExportOutput);
}
protected
string
RemoveColumnHeader(
string
str)
{
int
i = str.IndexOf(
"<thead>"
);
while
(i > 0)
{
str = str.Substring(0, str.IndexOf(
"<thead>"
)) + str.Substring(str.IndexOf(
"</thead>"
) + 8);
i = str.IndexOf(
"<thead>"
);
}
return
str;
}
Thanks,
Jayesh Goyani
Please, review the following help topic(section Hiding items) to see what approach is used. In your case the code need little modification to fit your needs, namely:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridHeaderItem)
{
e.Item.Display =
false
;
}
}
All the best,
Andrey
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>