Hi!
I could use some assistance if anyone is able to help. In my application I have a grid displaying a number of columns. There is a requirement for the users to be able to select any number of columns and then export the selected columns to PDF or Excel. To enable selection of columns, I added a checkbox into the HeaderTemplate of a GridItemTemplateColumn for each column.
By the way, the code displayed in this is a simplified version I created in an attempt to identify the issue. :)
Here is the markup for my RadGrid
And here is the code behind:
The issue I am having is that when the columns are exported instead of the HeaderText being displayed, "False" is displayed. I've attached a screenshot of the PDF output.
To sum it up: I want the column's header text to display in the exported files instead of the text "False", but I can't figure out what I am doing wrong or if there is a better way to achieve this.
Thanks.
Kevin
I could use some assistance if anyone is able to help. In my application I have a grid displaying a number of columns. There is a requirement for the users to be able to select any number of columns and then export the selected columns to PDF or Excel. To enable selection of columns, I added a checkbox into the HeaderTemplate of a GridItemTemplateColumn for each column.
By the way, the code displayed in this is a simplified version I created in an attempt to identify the issue. :)
Here is the markup for my RadGrid
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"ID"
AllowFiltering
=
"true"
HeaderStyle-Width
=
"100"
SortExpression
=
"ID"
FilterControlWidth
=
"50"
HeaderText
=
"ID"
>
<
HeaderTemplate
>
<
asp:CheckBox
ID
=
"IDCheck"
runat
=
"server"
CssClass
=
"HeaderCheckBox"
Text
=
"ID"
/>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"IDLabel"
runat
=
"server"
Text='<%# Eval("ID") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Name"
AllowFiltering
=
"true"
HeaderStyle-Width
=
"100"
SortExpression
=
"ID"
FilterControlWidth
=
"50"
HeaderText
=
"Name"
>
<
HeaderTemplate
>
<
asp:CheckBox
ID
=
"NameCheck"
runat
=
"server"
CssClass
=
"HeaderCheckBox"
Text
=
"Name"
/>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"NameLabel"
runat
=
"server"
Text='<%# Eval("Name") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"RandomText"
AllowFiltering
=
"true"
HeaderStyle-Width
=
"100"
SortExpression
=
"RandomText"
FilterControlWidth
=
"50"
HeaderText
=
"RandomText"
>
<
HeaderTemplate
>
<
asp:CheckBox
ID
=
"RandomTextCheck"
runat
=
"server"
CssClass
=
"HeaderCheckBox"
Text
=
"Random"
/>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"RandomTextLabel"
runat
=
"server"
Text='<%# Eval("RandomText") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:Button
ID
=
"PDFExportButton"
runat
=
"server"
OnClick
=
"ExportToPDF"
Text
=
"Export to PDF"
/>
<
asp:Button
ID
=
"ExcelExportButton"
runat
=
"server"
OnClick
=
"ExportToExcel"
Text
=
"Export to Excel"
/>
And here is the code behind:
public
partial
class
Default : System.Web.UI.Page
{
protected
override
void
OnInit(EventArgs e)
{
RadGrid1.DataSource = GetDataSource();
RadGrid1.DataBind();
base
.OnInit(e);
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
List<Person> GetDataSource()
{
List<Person> peeps =
new
List<Person>();
for
(
int
i = 0; i < 10; i++)
{
Person p =
new
Person
{
Name =
"Test"
+ i.ToString(),
ID = i,
RandomText = DateTime.Now.Millisecond.ToString()
};
peeps.Add(p);
}
return
peeps;
}
protected
void
ExportToPDF(
object
sender, EventArgs e)
{
RadGrid1.ExportSettings.ExportOnlyData =
true
;
RadGrid1.ExportSettings.HideStructureColumns =
true
;
RadGrid1.ExportSettings.IgnorePaging =
true
;
//RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToPdf();
}
protected
void
ExportToExcel(
object
sender, EventArgs e)
{
RadGrid1.ExportSettings.ExportOnlyData =
true
;
RadGrid1.ExportSettings.HideStructureColumns =
true
;
RadGrid1.ExportSettings.IgnorePaging =
true
;
//RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();
}
}
The issue I am having is that when the columns are exported instead of the HeaderText being displayed, "False" is displayed. I've attached a screenshot of the PDF output.
To sum it up: I want the column's header text to display in the exported files instead of the text "False", but I can't figure out what I am doing wrong or if there is a better way to achieve this.
Thanks.
Kevin