This is a migrated thread and some comments may be shown as answers.

Export option in radgrid

1 Answer 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Badrinarayanan
Top achievements
Rank 1
Badrinarayanan asked on 24 Jul 2008, 12:55 PM
 

I have a radgrid which is

<radG:RadGrid TabIndex="11" ID="RadGrdFiltered" Skin="Glassy" EnableAJAX="True" AutoGenerateColumns="False"

LoadingTemplateTransparency="20" ItemStyle-Height="20px" AlternatingItemStyle-Height="20px"

AllowMultiRowEdit="false" AllowMultiRowSelection="true" MasterTableView-RetrieveAllDataFields="true"

EnableOutsideScripts="false" EnableAJAXLoadingTemplate="false" runat="server" AllowSorting="false"

AllowPaging="true" PageSize="10">

<ExportSettings OpenInNewWindow="true" ExportOnlyData="true" />

<MasterTableView Width="100%" HorizontalAlign="NotSet" AutoGenerateColumns="false"

AllowAutomaticDeletes="True" CssClass="master">

<Columns>

<radG:GridBoundColumn HeaderText="ID" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="ID" SortExpression="ID" HeaderStyle-Width="10%" />

<radG:GridBoundColumn HeaderText="First Name" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="First Name" SortExpression="First Name" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Last Name" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Last Name" SortExpression="Last Name" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Plan Type" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Plan Type" SortExpression="Plan Type" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Status" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Status" SortExpression="Status" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Division" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Division" SortExpression="Division" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Department" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Department" SortExpression="Department" HeaderStyle-Width="12%" />

<radG:GridBoundColumn HeaderText="Location" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle"

DataField="Location" SortExpression="Location" HeaderStyle-Width="32%" />

</Columns>

</MasterTableView>

<AlternatingItemStyle Height="20px" />

<ItemStyle Height="20px" />

</radG:RadGrid>

Now I tried to export the data in the radgrid to excel using a button click event.  The event is

protected

void btnExport_Clicked(object sender, EventArgs e)

{

 

RadGrdFiltered.ExportSettings.IgnorePaging =

true;

RadGrdFiltered.ExportSettings.OpenInNewWindow =

true;

RadGrdFiltered.MasterTableView.ExportToExcel();

RadGrdFiltered.ExportSettings.FileName =

"QBOutput" + DateTime.Now.ToFileTime() + ".xls";

}

But inspite of giving these things, i am not able to achieve the result. 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Jul 2008, 02:36 PM
Hello Badrinarayanan,

Please give us more details concerning the behavior you expected. I made an example based on your code and it seems that your approach is correct. I would only like to mention that if you want to set your custom file name you should replace these two lines like shown below:

RadGrdFiltered.ExportSettings.FileName = "QBOutput" + DateTime.Now.ToFileTime() + ".xls"
RadGrdFiltered.MasterTableView.ExportToExcel(); 

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Badrinarayanan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or