Export Radgrid in PDF, Word, CSV, Excel format
Export Radgrid in PDF, Word, CSV, Excel format
Telerik Radgrid provide many predefined function and properties
for simplifying working with Telerik control. For exporting Radgrid in different format we just need to call its function.
Step 1: Design web form .aspx page
<div>
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1"
runat="server"
CellSpacing="0"
Width="50%"
PagerStyle-AlwaysVisible="true"
ShowFooter="true"
GridLines="None"
AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource">
<HeaderStyle
HorizontalAlign="Left"
/>
<ExportSettings
HideStructureColumns="true">
</ExportSettings>
<MasterTableView
DataKeyNames="name"
AutoGenerateColumns="false">
<NoRecordsTemplate>
No records found.</NoRecordsTemplate>
<HeaderStyle
BackColor="#8EDDFF"
Font-Bold="true"
/>
<ItemStyle
BackColor="#B2F4FF"
Font-Italic="true"
/>
<Columns>
<telerik:GridBoundColumn Aggregate="Count"
DataField="Name"
HeaderText="Name"
FooterText="Total
Count: ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn Aggregate="Sum"
DataField="Amount"
HeaderText="Amount"
DataType="System.Int32"
FooterText="Total
Amount: ">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="UnitCount"
DataField="UnitCount"
/>
<telerik:GridBoundColumn HeaderText="Phone"
DataField="Phone"
/>
<telerik:GridCalculatedColumn
HeaderText="Total
Price" UniqueName="TotalPrice" DataType="System.Double"
DataFields="Amount,
UnitCount" Expression="{0}*{1}" FooterText="Total : " Aggregate="Sum">
</telerik:GridCalculatedColumn>
</Columns>
<ItemStyle
BackColor="#DFDFDF"
/>
<HeaderStyle
BackColor="#FFFFFF"
ForeColor="#767676"
/>
<AlternatingItemStyle
BackColor="#FFFFFF"
/>
</MasterTableView>
</telerik:RadGrid>
</div>
<br />
<br />
<telerik:RadButton ID="btn_pdf"
runat="server"
Text="Download
PDF" OnClick="pdf_Click">
</telerik:RadButton>
<telerik:RadButton ID="RadButton1"
runat="server"
Text="Download
Excel" OnClick="exl_Click">
</telerik:RadButton>
<telerik:RadButton ID="RadButton2"
runat="server"
Text="Download
Word" OnClick="word_Click">
</telerik:RadButton>
<telerik:RadButton ID="RadButton3"
runat="server"
Text="Download
Csv" OnClick="csv_Click">
</telerik:RadButton>
</div>
Step 2: ogic on .CS page
//For Dtabinding to Radgrid
protected void
RadGrid1_NeedDataSource(object sender,
Telerik.Web.UI.GridNeedDataSourceEventArgs
e)
{
DataTable dt = new
DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Amount", typeof(Int32));
dt.Columns.Add("Phone");
dt.Columns.Add("UnitCount",
typeof(Int32));
dt.Rows.Add("Kandy", "12", "8802***2564",
"2");
dt.Rows.Add("Sam",
"25", "545502*2544",
"4");
dt.Rows.Add("Izhar", "32", "95802*2452",
"4");
dt.Rows.Add("Vineet", "10", "88022564***",
"6");
RadGrid1.DataSource = dt;
}
//For Pdf Format
protected void
pdf_Click(object sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToPdf();
}
//For Excel Format
protected void
exl_Click(object sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToExcel();
}
//For Word Format
protected void
word_Click(object sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToWord();
}
//For Csv Format
protected void
csv_Click(object sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToCSV();
}
}
Comments
Post a Comment