当Telerik radgrid中的动态生成列为true时,我需要在页脚显示Row total。
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" OnNeedDataSource="RadGrid1_OnNeedDataSource"> <MasterTableView AutoGenerateColumns="true"> </MasterTableView> </telerik:RadGrid>
答案 0 :(得分:1)
请尝试使用以下代码段。
<强> ASPX 强>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" OnNeedDataSource="RadGrid1_NeedDataSource"
OnColumnCreated="RadGrid1_ColumnCreated">
<MasterTableView AutoGenerateColumns="true"></MasterTableView>
</telerik:RadGrid>
<强> ASPX.CS 强>
protected void Page_Load(object source, System.EventArgs e)
{
if (!IsPostBack)
{
RadGrid1.ShowFooter = true;
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name ="Name2"}
};
RadGrid1.DataSource = data;
}
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
if (e.Column.DataType.Name == "Int32")
{
GridBoundColumn bndcol = (GridBoundColumn)e.Column;
bndcol.Aggregate = GridAggregateFunction.Sum;
}
}
如果有任何疑虑,请告诉我。