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.
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
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:
C#:
Thanks,
Shinu
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:
but when I don't set the text, and setup the link:
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:
So you can see, you'll only get something in the export excel file, IF,
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?
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
<
td
><a href="1234"></a></
td
>
So you can see, you'll only get something in the export excel file, IF,
<
td
>
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
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
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.