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

Export Tooltip value of a cell in Export to Excel functionality

12 Answers 716 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siva
Top achievements
Rank 1
Siva asked on 25 Mar 2013, 07:07 AM
Hi,
     I am having a grid in which the cell value is very long string so i used Tooltip to display the full string, only 15 characters are displayed in the grid by using substring function.. On Exporting the GRID to EXcel i Got only the 15 characters data as the cell value instead i need the Tooltip value (i.e) full string value in the EXCEL. Please help me with a code.. Thanx in advance..

12 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Mar 2013, 01:01 PM
Hello,

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                item["ID"].Text = item["ID"].ToolTip; //ID is column Unique Name
            }
        }
    }


Thanks,
Jayesh Goyani
0
Siva
Top achievements
Rank 1
answered on 26 Mar 2013, 06:13 AM
Hi ,
I am having that export to Excel button outside the Grid , how can i use it..?
Thanx in advance..
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2013, 06:52 AM
Hi,

Try the following code.
C#:
protected void Button2_Click(object sender, EventArgs e)
   {
      foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
       {
           item["ID"].Text = item["ID"].ToolTip;
       }
       RadGrid1.ExportSettings.ExportOnlyData = true;
       RadGrid1.MasterTableView.ExportToExcel(); 
       RadGrid1.MasterTableView.Rebind();
   }

Thanks,
Shinu
0
Siva
Top achievements
Rank 1
answered on 26 Mar 2013, 12:51 PM
No its not working , I still got the same 15 characters in the Excel sheet..
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Mar 2013, 08:26 PM
Hello,

can you please provide your code ?

Thanks,
Jayesh Goyani
0
Siva
Top achievements
Rank 1
answered on 27 Mar 2013, 06:10 AM
aspx file:

<telerik:RadGrid ID="RadGrid1" runat="server" OnPageIndexChanged="RadGrid1_PageIndexChanged"

 

AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"

CellSpacing="0" AllowAutomaticUpdates="True"

OnNeedDataSource="RadGrid1_NeedDataSource"

OnUpdateCommand="RadGrid1_UpdateCommand"  GridLines="Both" >
.
;
:

 

<telerik:GridTemplateColumn  HeaderText="Donor" UniqueName="Donor ">

<ItemTemplate>

<asp:Label ID="lblDonorName" ToolTip='<%# Eval("Donor_name")%>' Text='<%# Eval("dnrName")%>' runat="server"></asp:Label>

</ItemTemplate>

</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn HeaderText="Description" UniqueName=" Description">

<ItemTemplate>

<asp:Label ID="lblDesc" ToolTip='<%# Eval("descr")%>' Text='<%# Eval("Desc")%>' runat="server"></asp:Label>

</ItemTemplate>

</telerik:GridTemplateColumn>
:
:
</telerik:RadGrid >

Aspx.cs file
---------------

protected void btnExport_Click(object sender, EventArgs e)

{

foreach (GridDataItem item in RadGridGift.MasterTableView.Items)

{

item["Donor"].Text = item["Donor"].ToolTip; // column Unique Name

item["Description"].Text = item[" Description"].ToolTip;

}

      

RadGrid1.ExportSettings.ExportOnlyData =

true;

RadGrid1.ExportSettings.IgnorePaging =

true;

RadGrid1.ExportSettings.OpenInNewWindow =

true;

RadGrid1.MasterTableView.AllowPaging =

false;

RadGrid1.MasterTableView.ExportToExcel();

RadGrid1.Rebind();

}

 

0
Siva
Top achievements
Rank 1
answered on 27 Mar 2013, 09:33 AM
I tried this code:

Aspx.cs
--------------
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)

{

if(e.FormattedColumn.UniqueName) == "Donor")

 

{

e.Cell.Text = e.Cell.ToolTip;

}

if ((e.FormattedColumn.UniqueName) == "Description")

{

e.Cell.Text = e.Cell.ToolTip;

}
}

It gives a empty cell in those particular columns.. but when i tried to give any hard code values instead of e.cell.Tooltip it reflects in the Excel sheet please help me to correct this .. Thnx in Advance..

0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Mar 2013, 05:12 PM
Hello,

Please try with any code snippet.


protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            
                    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                      {
                      item["Donor"].Text = (item.FindControl("lblDonorName") as Label).ToolTip;
                     item["Description"].Text = (item.FindControl("lblDesc") as Label).ToolTip;
                    }
        }
    }

protected void Button2_Click(object sender, EventArgs e)
   {
     
       RadGrid1.MasterTableView.ExportToExcel();
       
   }

OR

protected void Button2_Click(object sender, EventArgs e)
   {
      
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                      {
                      item["Donor"].Text = (item.FindControl("lblDonorName") as Label).ToolTip;
                     item["Description"].Text = (item.FindControl("lblDesc") as Label).ToolTip;
                    }


       RadGrid1.ExportSettings.ExportOnlyData = true;
       RadGrid1.MasterTableView.ExportToExcel();
       RadGrid1.MasterTableView.Rebind();
   }


Thanks,
Jayesh Goyani
0
Siva
Top achievements
Rank 1
answered on 28 Mar 2013, 12:43 PM
no not working both the codes..
same prob only the tooltip values are not fetching if i give any hardcode value it showing..
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 Mar 2013, 06:23 PM
Hello,

Please check below demo.

https://skydrive.live.com/redir?resid=977B16A5E89A5236!110

Thanks,
Jayesh Goyani
0
Siva
Top achievements
Rank 1
answered on 01 Apr 2013, 11:07 AM
I think my Problem is , The Grid contains empty cell in which i set the tooltip, so when i used this code it throws system.nullreferenceException error &

Object reference not set to an instance of an object.

I am using Ongridexportcellformatting

Aspx.cs
----------

 

protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)

 

{

GridDataItem item = e.Cell.Parent as GridDataItem;

 

 

if ((e.FormattedColumn.UniqueName) == "Donor")

{

TableCell Cell = item["Donor Name"];

 

if (Cell != null && Cell.Text != "")

Cell.Text =

(item.FindControl("lblDonor") as Label).ToolTip;

}

if ((e.FormattedColumn.UniqueName) == "Description")

{

TableCell Cell = item["Description"];

if (Cell.Text != "")

Cell.Text = (item.FindControl(

"lblDesc") as Label).ToolTip;

}
when i use cell.text="any value";
it reflects in the exported excel but not the tooltip value even i put the (item.FindControl(

"lblDesc") as Label).ToolTip;

 

.. Help me with a code to solve this . Thnx in advance..

0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Apr 2013, 06:51 PM
Hello,

Can you please provide your whole grid code ?

Thanks.
Jayesh Goyani
Tags
Grid
Asked by
Siva
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Siva
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or