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

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

I am having that export to Excel button outside the Grid , how can i use it..?
Thanx in advance..

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


can you please provide your code ?
Thanks,
Jayesh Goyani

<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();
}

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..

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

same prob only the tooltip values are not fetching if i give any hardcode value it showing..

Please check below demo.
https://skydrive.live.com/redir?resid=977B16A5E89A5236!110
Thanks,
Jayesh Goyani

Object reference not set to an instance of an object.
I am using OngridexportcellformattingAspx.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..

Can you please provide your whole grid code ?
Thanks.
Jayesh Goyani