2011-11-05 65 views
1

我radgrid控件(Telerik的)是象下面這樣:Telerik RadGrid - >如何SUM(nvarchar)頁腳在頁腳?

<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),我希望在詳細信息表的頁腳中有文件大小的總和。
但啓用此詳細信息表中的頁腳並將FileSize列的聚合設置爲總和,我得到一個錯誤,告訴您不能有對象值的總和!
有沒有辦法使FileSize列的總和?

回答

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