c# - 如何在 CodeBehind 的 DetailTable 中访问 FooterText (Telerik-RadGrid)?

标签 c# asp.net telerik footer radgrid

我的 asp.net web 表单中有一个 Telerik RadGrid,如下所示:

MasterTableView
           DetailTables -> GridTableView

在那个细节表中,我有一列如下:

                            <telerik:GridTableView runat="server" DataKeyNames="ID,Customer_ID,CardType_ID,OrderStatus_ID"
                                DataSourceID="sdsOrders" AllowFilteringByColumn="True" 
                                AllowMultiColumnSorting="True" AllowSorting="True" ShowFooter="True" OnDataBinding="GridTableView_DataBinding">  
...   

                            <telerik:GridBoundColumn DataField="TotalPrice" DataType="System.Int32" FilterControlAltText="Filter TotalPrice column"
                                HeaderText="TotalPrice" SortExpression="TotalPrice" 
                                UniqueName="TotalPrice" AllowFiltering="False" FooterText="Sum: " Aggregate="Sum">
                                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            </telerik:GridBoundColumn>

我想更改页脚文本 (Sum) 和页脚 (Sum) 的颜色。
对于 MasterTableView 中的 DataBoundColumns,下面的代码有效:

protected void GridTableView_DataBinding(object sender, EventArgs e)
{
    GridBoundColumn TotalPrice = grdCustomers.MasterTableView.GetColumnSafe("TotalPrice") as GridBoundColumn;
    TotalPrice.FooterAggregateFormatString = "<span class=\"AggregateTitleColor\">Sum : </span>" + "{0:#,0 ;#,0- }";
    TotalPrice.FooterStyle.ForeColor = ColorTranslator.FromHtml("blue");
}

现在如何为 DetailTable 中的 TotalPrice 重写这些代码?

提前致谢

最佳答案

我找到了答案:
首先应该在 MasterTableView 中使用 DataBinding。
并像这样重写代码:

protected void MasterTableView_DataBinding(object sender, EventArgs e)  <- Pay Attention Here
{
    GridBoundColumn TotalPrice = grdCustomers.MasterTableView.DetailTables[0].GetColumnSafe("TotalPrice") as GridBoundColumn;
    TotalPrice.FooterAggregateFormatString = "<span class=\"AggregateTitleColor\">Sum : </span>" + "{0:#,0 ;#,0- }";
    TotalPrice.FooterStyle.ForeColor = ColorTranslator.FromHtml("blue");
}

你就完成了。

关于c# - 如何在 CodeBehind 的 DetailTable 中访问 FooterText (Telerik-RadGrid)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234661/

相关文章:

c# - 正则表达式来获取样本的特定部分

c# - 如何在 Telerik RadGrid 中显示分层类字段?

javascript - 在带有数据的 JavaScript 中将行添加到剑道网格

c# - ASP.Net 上的预编译和启动时间

c# - 如何修复代码以便 C# 中的斐波那契搜索算法正常​​工作

asp.net - 自定义错误页面未显示

asp.net - VB.Net MailMessage文本编码问题

asp.net - 如何在站点之间共享用户控件/功能?

c# - DotNetZip:将文件添加到动态创建的存档目录

c# - 使用 C# 连接到 OPENVPN