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

export a single record to a pdf file or excel file

1 Answer 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
areen
Top achievements
Rank 1
areen asked on 22 Feb 2011, 09:15 AM
hi,

i need to export a single records detail to either a pdf file or an excel file.

i'm using the radgrid control and have used the edit form template to display detail information for a single record. i'd like to put the export button here and export only this record's data.

how can this be done?

thanks,
areen

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Feb 2011, 09:55 AM
Hello Areen,

One option is you can hide all the rows in grid and export only the edit form like below.

ASPX:
<EditFormSettings EditFormType="Template">
    <FormTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%#Eval("EmployeeID") %>'></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
        <br />
        <asp:Button ID="ExportButton" runat="server" CommandName="ExportToExcel" Text="Export" />
    </FormTemplate>
</EditFormSettings>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == "ExportToExcel")
       {
           Button btn = (Button)e.CommandSource;
           btn.Visible = false;//hide Export button
           foreach (GridDataItem item in RadGrid1.Items)
           {
                item.Visible = false;
           }
       }
   }

-Shinu.
Tags
Grid
Asked by
areen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or