This is a migrated thread and some comments may be shown as answers.
Export radgrid with LinkButton
12 Answers 146 Views
This is a migrated thread and some comments may be shown as answers.
nader
Top achievements
Rank 1
nader asked on 08 Aug 2011, 05:11 PM
<telerik:GridTemplateColumn HeaderText="Employee" ItemStyle-Width="150px" UniqueName="EmployeeName">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lblEmpName" runat="server" Text="" />
                                        </ItemTemplate>
</telerik:GridTemplateColumn>
I have a radgrid with gridtemplate column of type linkbutton like the sample shown.
1)  When i export the grid to excel, the linkbuttons still linkable,underlined,blue color. I want to export like any label not linkable,not     underlined and change it's font color.

2) I want to add worksheets to my excel file with different data sources.

12 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 09 Aug 2011, 04:52 AM
Hello Nader,

You can achieve this in ExportCellFormatting event as shown below.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
 if (e.FormattedColumn.UniqueName == "EmployeeName")
 {
   TableCell cell = item["EmployeeName"];
   cell.Text = cell.Text;
 }
}

Thanks,
Princy.
0
nader
Top achievements
Rank 1
answered on 09 Aug 2011, 04:01 PM
What is item ?!?!
0
Accepted
Princy
Top achievements
Rank 1
answered on 10 Aug 2011, 04:53 AM
Hello Nader,

Sorry for the wrong code. Try the following code snippet to achieve your scenario.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{       
 GridDataItem item = e.Cell.Parent as GridDataItem;
 if (e.FormattedColumn.UniqueName == "EmployeeName")
 {
     TableCell cell = item["EmployeeName"];
     cell.Text = cell.Text;
 }
}

Thanks,
Princy.
0
Bruno
Top achievements
Rank 2
answered on 10 Aug 2011, 10:43 AM
¡Hola amigos!
This code is great, only thing I fail to understand is what is the purpose of cell.Text = cell.Text line?
Muchas gracias
0
nader
Top achievements
Rank 1
answered on 14 Aug 2011, 10:39 AM
Thanks princy.
0
Kanchan
Top achievements
Rank 1
answered on 24 Aug 2012, 12:08 PM
Hi Nader , can you please share the code how can you export link button text to excel.
0
Daniel
Telerik team
answered on 29 Aug 2012, 01:30 PM
Hello Kanchan,

Attached to this forum thread is a simple demo showing how you can export the linkbutton's text in a scenario similar to the original one.
Let me know whether this helps.

Kind regards,
Daniel
the Telerik team
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 their blog feed now.
0
Kanchan
Top achievements
Rank 1
answered on 15 Feb 2013, 01:14 PM
Hi Telerik team,

I am using window 7 with IE 9 and telerik  Q3 version (2012_3_1308,ddl from bin 35) and VS2010 .In my application we are using rad window .Rad Window is open but its show not properly.(not show header proper and lenth also not show proper).When using meta tag <meta http-equiv="X-UA-Compatible" content="IE=7" /> , rad window show properly but rad grid show blank.


Please help us for the same.

Thanks
Kanchan Prabha

0
Daniel
Telerik team
answered on 20 Feb 2013, 01:07 PM
Hello Kanchan,

This thread is focused on RadGrid export functionality. I would recommend that you open a new thread when your new question is not related to the previous one.
By the way, I'm unable to reproduce the problem on my end. It would be best if you can post some self-containing code that demonstrates this issue.

Best regards,
Daniel
the Telerik team
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 their blog feed now.
0
Keith
Top achievements
Rank 1
answered on 01 Oct 2013, 10:57 PM
So, I'm using the basic radgrid exportexcel. It all works, is awesome. My client asked me to edit the cell data. Currently empty data is represented as "--" and they want it to to be string.empty on the excel sheet.

My code:
 protected void radgrid_ExcelExportCellFormatting(object oExcelExportCellFormattingEventArgs e)
  {
            if (e.Cell.Text == "--")
                e.Cell.Text = string.Empty;
 
  }
 

The excel sheet still has "--" in the cells though. What am I doing wrong? The e.Cell is of type TableCell and the e.Cell.Text is the correct text needing to be changed and it is defined as a get/set. What's going on?

I also cannot use the GridDataItem method above due to the "--" can show up in all cells and the grid has some dynamic columns without a hardcoded uniqueName I can use.
0
Princy
Top achievements
Rank 1
answered on 03 Oct 2013, 09:56 AM
Hi Keith,

Please try the below sample code snippet,I was able to get the rows with no data as string.Empty.Please provide your full code snippet if this doesn't help.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" GridLines="None" AllowPaging="true" OnExcelExportCellFormatting="RadGrid1_ExcelExportCellFormatting" OnItemDataBound="RadGrid1_ItemDataBound">
    <ExportSettings IgnorePaging="true" ExportOnlyData="true" OpenInNewWindow="true">
    </ExportSettings>
    <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowExportToExcelButton="true">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate" />
            <telerik:GridBoundColumn DataField="OrderName" HeaderText="OrderName" UniqueName="OrderName" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                string content= item[col.UniqueName].Text;
                if (content == " ")
                {
                  item[col.UniqueName].Text = "--";
                }
 
            }
        }
    }
 
 protected void RadGrid1_ExcelExportCellFormatting(object sender, ExcelExportCellFormattingEventArgs e)
    {          
        if (e.Cell.Text == "--")
        {
            e.Cell.Text = string.Empty;
        }
    }

Thanks,
Princy
0
Keith
Top achievements
Rank 1
answered on 03 Oct 2013, 02:52 PM
Thank you for the example. We found where the issue is. We had a GridTemplatecolumn using an <%#Eval %> that broke the order of operations.
Tags
Grid
Asked by
nader
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
nader
Top achievements
Rank 1
Bruno
Top achievements
Rank 2
Kanchan
Top achievements
Rank 1
Daniel
Telerik team
Keith
Top achievements
Rank 1
Share this question
or