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

[Solved] Export functionality in grid

3 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siddharth
Top achievements
Rank 1
Siddharth asked on 21 May 2008, 02:17 AM
Hi guys,

I am a newbie to Telerik controls. I am trying to implement exporting functionality on the grid to export only selected rows to CSV format as follows:

<CommandItemTemplate> 
                                            <table cellpadding="2" cellspacing="1" style="font-family: Tahoma; font-size: 11px" 
                                                width="100%"
                                                <tr> 
                                                    <td style="text-align: left"
                                                        <asp:LinkButton ID="hlInsertBank" runat="server" CommandName="InitInsert" Text="Insert"></asp:LinkButton> 
                                                    </td> 
                                                    <td style="text-align: right"
                                                        <asp:LinkButton ID="exportBankDetails" runat="server" Text="Export" CommandName="ExportToCSV" ></asp:LinkButton> 
                                                    </td> 
                                                </tr> 
                                            </table> 

On the server-side I have handled ItemCommand event as follows:

protected void RadGrid_Bank_ItemCommand(object sender, GridCommandEventArgs e) 
    { 
        RadGrid grid = (RadGrid)sender; 
        int itemIndex = e.Item.ItemIndex; 
        if (e.CommandName == "ExportToCSV") 
        { 
            foreach (GridDataItem dataItem in grid.MasterTableView.Items) 
            { 
                dataItemdataItem.Display = dataItem.Selected; 
            } 
            grid.MasterTableView.ExportToCSV(); 
        } 
    } 

But when i click the export link after selecting a few rows, nothing happens. It shows me the loading panel. It also goes into the server-side code and executes ExportToCSV(). Also another strange thing happens - the grid reduces to the records I have selected i.e. the page initially is set to show 5 records, and I select only 2 of it to export, once the call comes back from the exportToCSV(), it shows me only the 2 records which were selected. Also, when moving to the next page and back, everything comes to normal.I can all my records again.

Any ideas on what I am doing wrong?

Regards,

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 May 2008, 06:03 AM
Hi Siddharth,

Can you try with the following code snippet and see whether it is workingor not?

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "ExportToCSV") 
        { 
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
            { 
                if (!item.Selected) 
                { 
                    item.Visible = false
                } 
            } 
            RadGrid1.ExportSettings.OpenInNewWindow = true
            RadGrid1.MasterTableView.ExportToCSV(); 
            
        } 
  } 


Thanks
Shinu.
0
Siddharth
Top achievements
Rank 1
answered on 21 May 2008, 06:53 AM
Hi Shinu,

It does nothing. I am still at the same place.
A point to note for you guys is that my grid is inside an AJAX Tab control. I am not sure if that is causing it.

Regards,
0
Princy
Top achievements
Rank 2
answered on 21 May 2008, 07:08 AM
Hi Siddharth,

Check out the following help document link.
Export from ajaxified grid

Thanks
Princy.
Tags
Grid
Asked by
Siddharth
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Siddharth
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or