i have a grid with 5 link button's in a row. When i export to excel i need this data in excel. But when i set
<ExportSettings IgnorePaging="True" ExportOnlyData = "true" OpenInNewWindow="true" >
I get empty data in my link button columns. When i set
<ExportSettings IgnorePaging="True" ExportOnlyData = "false" OpenInNewWindow="true" >
i get header and other junk images in the excel sheet.
I have tried setting the text as shown below:
protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem __item in grid.Items)
{
LinkButton eventIDLinkbutton = __item["EventID"].Controls[0] as LinkButton;
__item[
"EventID"].Text = eventIDLinkbutton.Text;
}
}But the EventID column is still empty. Could you please help me? Should i rebind the radgrid?
4 Answers, 1 is accepted
Please check below code snippet.
<telerik:GridTemplateColumn HeaderText="link" UniqueName="link">                        <ItemTemplate>                            <asp:LinkButton ID="lnk1" runat="server">test</asp:LinkButton>                        </ItemTemplate>                    </telerik:GridTemplateColumn>protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)    {        if (e.CommandName == RadGrid.ExportToExcelCommandName)        {            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)            {                item["link"].Text = (item.FindControl("lnk1") as LinkButton).Text;            }        }}Let me know if any concern.
Thanks,
Jayesh Goyani
Thanks for the reply.
I tried that piece of code.
item.FindControl(
"lnk1") as LinkButton results in null .The below 2 lines work for me, in debug mode i see that the text is set as well but i do not see the data in the excel sheet.
LinkButton eventIDLinkbutton = __item["lnk1"].Controls[0] as LinkButton;
 __item["link"].Text = eventIDLinkbutton.Text; 
Just to clarify, in the above example HeaderText and UniqueName are the same. I have a HeaderTemplate so by 
__item["link"], you mean the UniqueName right?
My structure is like this:
<
telerik:GridTemplateColumn UniqueName="SecondaryEvent1" ItemStyle-Width="10%" HeaderStyle-Width="10%"
ItemStyle-BackColor = "LightYellow" Visible = "false">
<HeaderTemplate>
<table>
<tr>
<td colspan = "3">
<asp:Label ID="lblProgramName1" runat="server"
Font-Bold="true"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="hdrDate1" runat="server" Text="hdrDate"
Width="50px"></asp:Label>
</td>
<td>
<asp:Label ID="hdrAdvID1" runat="server" Text="hdrAdvID"Width="40px"></asp:Label>
</td>
<td>
<asp:Label ID="hdrWB1" runat="server" Text="hdrWB Width="20px"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblDate1" runat="server" Width="40px"></asp:Label>
</td>
<td>
<asp:LinkButton ID="lblAdvID1" runat="server" Width="40px" CommandName="SecondaryEvent1" ForeColor = "Blue" />
</td>
<td>
<asp:Label ID="lblWB1" runat="server" Width="20px"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
item["lblAdvID1"].Text = (item.FindControl("lblAdvID1") as LinkButton).Text;Thanks,
Jayesh Goyani
That does not work either.
I am getting the below error:
__item["lblAdvID1"].Text = (__item.FindControl("lblAdvID1") as LinkButton).Text;
Cannot find a cell bound to column name 'lblAdvID1'. __item["lblAdvID1"].Text is throwing the exception.
Could you please tell me how to export to excel the below 2 columns:
<telerik:GridButtonColumn DataTextField="EventID" CommandName="SelectEvent" UniqueName="EventID" ItemStyle-ForeColor = "Blue" />   <telerik:GridTemplateColumn UniqueName="SecondaryEvent1" ItemStyle-Width="10%" HeaderStyle-Width="10%"  ItemStyle-BackColor = "LightYellow" Visible = "false">   <HeaderTemplate>   <table>   <tr>   <td colspan = "3">   <asp:Label ID="lblProgramName1" runat="server"   Font-Bold="true"></asp:Label>   </td>   </tr>   <tr>   <td>   <asp:Label ID="hdrDate1" runat="server" Text='<%# GetGlobalResource("pgLISASearchEvents","hdrDate") %>'  Width="50px"></asp:Label>   </td>   <td>   <asp:Label ID="hdrAdvID1" runat="server" Text='<%# GetGlobalResource("pgLISASearchEvents","hdrAdvID") %>'  Width="40px"></asp:Label>     </td>   <td>   <asp:Label ID="hdrWB1" runat="server" Text='<%# GetGlobalResource("pgLISASearchEvents","hdrWB") %>'  Width="20px"></asp:Label>   </td>   </tr>     </table>   </HeaderTemplate>   <HeaderStyle HorizontalAlign="Center" />   <ItemTemplate>   <table>   <tr>   <td>   <asp:Label ID="lblDate1" runat="server" Width="40px"></asp:Label>   </td>   <td>     <asp:LinkButton ID="lblAdvID1" runat="server" Width="40px" CommandName="SecondaryEvent1" ForeColor = "Blue" />   </td>   <td>   <asp:Label ID="lblWB1" runat="server" Width="20px"></asp:Label>   </td>   </tr>   </table>   </ItemTemplate>   </telerik:GridTemplateColumn> The values of GridButtonColumn and the value of the label lblAdvID1 in GridTemplateColumn SecondaryEvent1 are not being exported to excel.