【发布时间】:2014-11-20 15:23:57
【问题描述】:
我对整个 Web 应用程序中多个 Telerik RadGrids 上的某些数据进行了一些自定义转换和格式化。在使用 Telerik 之前,我使用了标准的 ASP.NET GridView。为了在使用GridView 时进行自定义转换和格式化,我从BoundField 派生了一个新类并覆盖了FormatDataValue 和GetValue 方法。通过这种方式,我可以从绑定的数据源中截取网格单元格的值,在网格看到它时更改值,并应用我的自定义格式规则。然后,每当我需要对特定网格列使用此功能时,我都会使用我的自定义 BoundField。
我没有看到 Telerik GridBoundColumn 的任何方法来覆盖和拦截网格从绑定数据源获取数据的点(相当于 GridView 的 BoundField.GetValue 方法)。 我需要单元格数据在 Telerik 网格中显示为所有功能的值 B - 显示、排序、过滤、分组等 - 即使数据源中的相应数据是值 A,我也无法更改以任何方式的底层数据源。
使用 ASP.NET GridView 的 BoundField 编写代码 sn-ps:
public class MyBoundField
: BoundField
{
protected override string FormatDataValue(object dataValue, bool encode)
{
if ( someCondition )
{
return MyFormatFunction(dataValue, encode);
}
else
{
return base.FormatDataValue(dataValue, encode);
}
}
protected override object GetValue(Control controlContainer)
{
// Get the data bound value.
object boundValue = base.GetValue(controlContainer);
// Convert the value for the grid's usage.
object convertedValue = MyConversionFunction(boundValue);
return convertedValue;
}
}
用法:
<asp:GridView ... >
<asp:BoundField .... />
<custom:MyBoundField .... />
</asp:GridView>
Telerik 选项:
public class MyGridBoundColumn
: GridBoundColumn
{
protected override string FormatDataValue(object dataValue, GridItem item)
{
if ( someCondition )
{
return MyFormatFunction(dataValue, item);
}
else
{
return base.FormatDataValue(dataValue, item);
}
}
// Override what method in order to convert the value for all grid functionality????
}
问题:
如何在 RadGrid 中使用 Telerik GridBoundColumn 执行相当于 BoundField.GetValue 的操作?如果没有真正的等价物,有哪些可用选项?
【问题讨论】:
标签: asp.net gridview webforms telerik radgrid