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

Export using item template Button

5 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sam
Top achievements
Rank 1
sam asked on 18 Oct 2010, 12:32 PM
i am stuck i need to export a selected row using item template of RadGrid
please help me to export a row from the grid on clicking the button

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Oct 2010, 01:25 PM
Hello Sam,

Try the following code snippets for exporting only one row which is selected using the Button inside ItemTemplate .

ASPX:
<telerik:GridTemplateColumn>
   <ItemTemplate>
       <asp:LinkButton ID="LinkButton1" runat="server"
         CommandName="Export">ExportToExcel</asp:LinkButton>
   </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
      if (e.CommandName == "Export")
       {
           GridDataItem item=(GridDataItem)e.Item;
           foreach (GridDataItem allitem in RadGrid1.MasterTableView.Items)
           {
               if (item.ItemIndex != allitem.ItemIndex)
                   allitem.Visible = false;
           }
           RadGrid1.ExportSettings.OpenInNewWindow = true;
           RadGrid1.MasterTableView.ExportToExcel(); // exporting to Excel

       }
   }

Thanks,
Princy.
0
sam
Top achievements
Rank 1
answered on 19 Oct 2010, 06:31 AM
HI shinu  i tried your code but on click nothing happen
can u please post me full ASPX code or zip

thank you in return
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Oct 2010, 07:39 AM
Hello Sam,

Here is the complete code that I tried.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="false"
   DataSourceID="SqlDataSource1" OnItemCommand="RadGrid1_ItemCommand">
   <MasterTableView CommandItemDisplay="Top" DataKeyNames="EmployeeID">
       <Columns>
          <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID">
          </telerik:GridBoundColumn>
          <telerik:GridTemplateColumn>
            <ItemTemplate>
               <asp:LinkButton ID="LinkButton1" runat="server" CommandName="ExportToExcel">ExportToExcel</asp:LinkButton>
            </ItemTemplate>
          </telerik:GridTemplateColumn>
        </Columns>
     </MasterTableView>
  </telerik:RadGrid>

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.ExportToExcelCommandName)
       {
           GridDataItem item = (GridDataItem)e.Item;
           foreach (GridDataItem allitem in RadGrid1.MasterTableView.Items)
           {
               if (item.ItemIndex != allitem.ItemIndex)
                   allitem.Visible = false;
           }
 
           RadGrid1.ExportSettings.OpenInNewWindow = true;
           RadGrid1.MasterTableView.ExportToExcel();
       }
   }

Thanks,
Princy.
0
sam
Top achievements
Rank 1
answered on 19 Oct 2010, 09:40 AM
Shinu thanks  is there anyway to use a Button to generate an excel sheet outside RadGrid
for example if inside the grid there are 5 unique rows
i want on clicking this button to generate at same time 5 excel sheets  (1  row per sheet)
0
Daniel
Telerik team
answered on 21 Oct 2010, 12:59 PM
Hello Sam,

You cannot create additional worksheets out-of-the-box however you can do that manually as demonstrated in the following code-library:
Multiple worksheets in ExcelML

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
sam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
sam
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or