public bool IsPassed {get;set;}
public bool HasPassport {get;set;}
when the grid is loaded or searhced these two cols display an image icon when the value is true.
while exporting to excel if IsPassed = true..then I have to show "Yes" in the excel else empty
if HasPassport = true, then I have to display some string value like "hdgfjhgh"
can anyone give me an example how to do it ?
10 Answers, 1 is accepted
To override the default export, you can subscribe for the ElementExporting event of RadGridView and set the e.Value to be exported as you would like to.
Regards,
Didie
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Am using CSExcelExportUtilities.GetExcelMLFromGridView()
CSExcelExportUtilities.ExportToExcel()
this method to export to excel.
Can I override the value here as i have access to the grid ? How to do that
If you have access to RadGridView, then you can subscribe for its ElementExporting event. The only way to override the value that is exported is through this event (setting a proper e.Value instead the one that is coming by default). You can check our Exporting WPF Demos for some examples on how to customize the export.
Regards,
Didie
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Thanks
I am not sure I understand your question. You say with the e.Value you can update the column header or style etc. Actually you can change any value that is going to be exported. Do you have a problem changing the value when you have subscribed for the ElementExporting event?
Regards,
Didie
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
File || Name ||
----------------------------
Yes || xyx ||
In order to not override the headers you need to change the e.Value only when the e.Element is ExportElement.Cell.
For example:
private
void
clubsGrid_ElementExporting(
object
sender, GridViewElementExportingEventArgs e)
{
if
(e.Element == ExportElement.Cell)
{
var column = e.Context
as
GridViewDataColumn;
if
(column !=
null
&& column.Header.ToString()==
"File"
)
{
if (e.Value == true)
{
e.Value =
"Yes"
;
}
}
}
}
How does this work for you?
Regards,
Didie
Telerik
Hi,
I have the same requirement, but am using Format="Xlsx" and trying to accomplish this same task using the OnInfrastructureExporting event handler as follows:
protected void grdUserAdmin_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
{
var colCount = e.ExportStructure.Tables[0].Columns.Count;
var rowCount = e.ExportStructure.Tables[0].Rows.Count;
ExportStyle headerStyle = new ExportStyle();
headerStyle.ForeColor = Color.White;
headerStyle.BackColor = Color.Blue;
headerStyle.Font.Bold = true;
// Set the header style for all columns
for (var i = 1; i <= colCount; i++)
{
e.ExportStructure.Tables[0].Cells[i, 1].Style = headerStyle;
e.ExportStructure.Tables[0].Columns[i].Width = 200; // Would like auto-width !!
}
// Place an "X" in cells assigned to a boolean data field if value is true
var headerText = "";
for (var c = 1; c <= colCount; c++)
{
for (var r = 1; r <= rowCount; r++)
{
if (r == 1)
{
headerText = e.ExportStructure.Tables[0].Cells[c, r].Value.ToString();
continue;
}
if (headerText == "Active")
{
var x = e.ExportStructure.Tables[0].Cells[c, r].Value.ToString();
System.Diagnostics.Debug.WriteLine("Cell Value: " + x);
if (Convert.ToBoolean(e.ExportStructure.Tables[0].Cells[c, r].Value.ToString()))
e.ExportStructure.Tables[0].Cells[c, r].Value = "X";
}
}
}
}
The value for the variable x above is always "" or null (hard to tell in the Output section of VS).
I know that my data for column Active should have all true values.
The conversion to boolean fails!
I think I'm close.
What am I doing wrong?
Thanks in advance for any advice.
Jim
As this forum thread is for the Telerik UI for WPF suite, can you please repost your question in the relevant forum section which I believe is the UI for ASP.NET AJAX?
Thank you in advance for your cooperation.
All the best,
Stefan X1
Telerik