我目前正在 Telerik RadGrid 中构建一个包含大量数据的 asp.net 应用程序。我的网格中的许多列包含大量文本。为了限制这些列中文本的大小(并保留网格的格式),我在以下代码段中截断了 ItemDataBound(...) 方法中的每个字段:
if (item["Title"].Text.Length > 21)
item["Title"].Text = item["Title"].Text.Substring(0, 21);
if (item["Investigation_Results"].Text.Length > 30)
item["Investigation_Results"].Text = item["Investigation_Results"].Text.Substring(0, 30);
if (item["Resolution_Steps"].Text.Length > 30)
item["Resolution_Steps"].Text = item["Resolution_Steps"].Text.Substring(0, 30);
问题是,当使用 RadGrid 的 Excel 导出功能时,被截断的字段在导出的 csv 中也会被截断。
问:如何在 GridView 中截断数据,但在导出到 Excel 时保持完整?
附加信息:
在此按钮单击事件上调用导出:
protected void imgbtnexcel_Click(object sender, ImageClickEventArgs e)
{
ConfigureExport();
RadGridActionItem.MasterTableView.ExportToExcel();
}
protected void ConfigureExport()
{
RadGridActionItem.ExportSettings.ExportOnlyData = true;
RadGridActionItem.ExportSettings.IgnorePaging = true;
RadGridActionItem.ExportSettings.OpenInNewWindow = true;
}
最佳答案
执行此操作的一种方法是处理 NeedDataSource 事件。在这种情况下,根据您是否要导出,为数据源提供完整或截断的文本。您没有提供此代码,但您应该能够判断您是否正在使用 GridExporting 事件、按钮单击事件或类似事件进行导出。
关于c# - 如何限制网格列中的文本长度而不限制 Excel 导出中的相同文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29517111/