Telerik RadGrid ->如何对页脚中的 (nvarchar) 列求和?

发布于 2024-12-14 06:42:47 字数 4660 浏览 0 评论 0原文

我的 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),我想在详细信息表的页脚中显示文件大小的总和。
但是在此详细信息表中启用页脚并将 FileSize 列的聚合设置为 Sum 后,我收到一条错误,告诉您不能获得对象值的总和!
有没有办法对 FileSize 列进行求和?

my radgrid(telerik) is like below :

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

this is a Hierarchy grid with two tables (one master and one detail).
i have a column in detail table named (FileSize)!
this column in my database is nvarchar(50), i want to have sum of file sizes in the footer of detail table.
but after enabling Footer in this detail table and set aggregate of FileSize Column to Sum, i got an error that tells you can not have sum of object values!
is there a way for make sum of FileSize Column?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2024-12-21 06:42:47

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

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;
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文