我的radgrid(telerik)如下所示:
<telerik:RadGrid ID="grdUsers" runat="server" GridLines="None" Skin="Vista" DataSourceID="sdsUsers"
AllowPaging="True" AutoGenerateColumns="False" OnItemCommand="grdUsers_ItemCommand"
Width="900px" AllowSorting="True" PageSize="20">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="sdsUsers">
<DetailTables>
<telerik:GridTableView runat="server" DataKeyNames="ID,User_ID" DataSourceID="sdsDownload"
ShowFooter="True">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="User_ID" MasterKeyField="ID" />
</ParentTableRelation>
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column"
HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="User_ID" DataType="System.Int32" FilterControlAltText="Filter User_ID column"
HeaderText="User_ID" SortExpression="User_ID" UniqueName="User_ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FileSize" FilterControlAltText="Filter FileSize column"
HeaderText="FileSize" SortExpression="FileSize" UniqueName="FileSize" Aggregate="Sum">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</telerik:GridTableView>
</DetailTables>
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="ID" FilterControlAltText="Filter ID column" HeaderText="ID"
SortExpression="ID" UniqueName="ID">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter FirstName column"
HeaderText="FirstName" SortExpression="FirstName" UniqueName="FirstName">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>
这是一个带有两个表(一个主表和一个表)的层次结构网格
我有一个名为(FileSize)的详细列表!
我的数据库中的这一列是nvarchar(50),我希望在详细信息页的页脚中有文件大小的总和。
但是在此详细信息表中启用Footer并将FileSize Column的聚合设置为Sum后,我收到一条错误消息,告诉您不能拥有对象值的总和!
有没有办法使FileSize列的总和?
答案 0 :(得分:1)
aspx:
<DetailTables>
<telerik:GridTableView Name="ChildGrid">
<Columns>
<telerik:GridTemplateColumn Aggregate="None" UniqueName="Name1">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
c#:
void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
if (item.HasChildItems)
{
bool flag = item.Expanded;
item.Expanded = true;
int csum = 0;
foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
{
csum += Convert.ToInt32((citem.FindControl("Label2") as Label).Text);
}
GridFooterItem cfooter = (GridFooterItem)item.ChildItem.NestedTableViews[0].GetItems(GridItemType.Footer)[0];
cfooter["Name1"].Text = csum.ToString();
item.Expanded = flag;
}
}
}