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

Export GridButtonColumn

3 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 20 Jun 2013, 07:07 PM
How to get Export working with GridButtonColumns ?  I want my LinkButton.Text data in the exported excel.


Shinu explains the problem here:
http://www.telerik.com/community/forums/aspnet-ajax/grid/exporting-data-to-excel.aspx#526940

but that link is not sufficient and does not present a solution.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jun 2013, 06:54 AM
Hi Ryan,

If you set the ExportOnlyData=true, you can export a GridButtonColumn using the ExporttoExcelCommand button.
Add an asp button for export and please try the code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  AutoGenerateColumns="false" >
        <MasterTableView >
               <Columns>
                   <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="ShippedDate" HeaderText="ShippedDate" UniqueName="ShippedDate">
                   </telerik:GridBoundColumn>
                   <telerik:GridButtonColumn UniqueName="del" Text="Delete" ButtonType="LinkButton" ></telerik:GridButtonColumn>
               </Columns>
        </MasterTableView>         
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Export" onclick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
   {      
    RadGrid1.MasterTableView.ExportToExcel();
   }

Thanks,
Shinu
0
Ryan
Top achievements
Rank 1
answered on 21 Jun 2013, 03:12 PM
Well it does work, but please understand, I cannot just set static text.

Now I am having a problem with the link, actually working as a link, b/c when I set the text, you end up getting this html markup:

<td>My text</td>


but when I don't set the text, and setup the link:

button.OnClientClick
the link works and I can see the link's text is correct, but when export nothing.  Now, when I setup the link the markup is like so:
<td><a href="1234"></a></td>


So you can see, you'll only get something in the export excel file, IF,
<td>
has a value inside it, besides a link.

Is there a way to get both to work?  I've tried setting the td value in the GridExporting(object sender, GridExportingArgs e) , but although I see in the debugger it's setting the text ( i.e. gridDataItem["mylinkcol"].Text = "1234" ) , it still does not show up in excel file .


Any ideas?
0
Kostadin
Telerik team
answered on 25 Jun 2013, 08:40 AM
Hello Ryan,

I prepared a small sample where I set DataTextField property of the ButtonColumn. The text is included into the exported file and the link is working as expected. I am attaching the sample to this thread, so you could try it on your end. Additionally could you please let me know which version of Telerik controls you are using?

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or