自动生成列时,页脚的Radgrid列总数为true

时间:2015-08-07 17:04:23

标签: c# telerik radgrid

当Telerik radgrid中的动态生成列为true时,我需要在页脚显示Row total。

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" OnNeedDataSource="RadGrid1_OnNeedDataSource"> <MasterTableView AutoGenerateColumns="true"> </MasterTableView> </telerik:RadGrid> 

1 个答案:

答案 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; 
    }
} 

如果有任何疑虑,请告诉我。