我需要向我的RadGrid
实例添加多个页脚行;不过,目前我只想添加第二个。我目前有一个页脚行,它正在完美地工作和显示,以供记录。
我在 Telerik 论坛上找到了以下相关问题并尝试实现它,但它不起作用:代码被执行,新代码FooterItem
被添加到第二行,Controls
但第二行没有出现。我需要找出原因,如果有人能帮我解决这个问题,我将不胜感激。
ASP 网格代码
<div id="OrderMainContent">
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1" />
<telerik:AjaxSetting AjaxControlID="txtQuantity">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadInputManager ID="RadInputManager1" runat="server">
<telerik:NumericTextBoxSetting BehaviorID="NumericBehavior1" Type="Number" DecimalDigits="0">
<TargetControls>
<telerik:TargetInput ControlID="RadGrid1" />
</TargetControls>
</telerik:NumericTextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Sunset" AllowSorting="True" AutoGenerateColumns="False"
GridLines="None" ShowFooter="True" OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender">
<MasterTableView DataKeyNames="ProductID" TableLayout="Fixed">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="colProduct" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblProduct %>"
HeaderStyle-HorizontalAlign="Center" DataField="ProdDesc">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="colQuantity" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblQuantity %>"
HeaderStyle-HorizontalAlign="Center" DataField="OrderQty" ColumnEditorID="txtQuantity">
<HeaderStyle Width="90" />
<ItemStyle Width="90px" />
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Width="50px" OnTextChanged="txtQuantity_TextChanged"
AutoPostBack="true">
</asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="colPrice" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblBasePrice %>"
HeaderStyle-HorizontalAlign="Center" DataField="ProdUnitPrice">
<HeaderStyle Width="80px" />
<ItemStyle Width="80px" />
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("ProdUnitPrice") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="colNotes" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblNotes %>"
HeaderStyle-HorizontalAlign="Center">
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
</telerik:RadGrid>
</div>
后面的相关代码
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
AddFooterRow(sender as RadGrid);
}
private void AddFooterRow(RadGrid grid)
{
if (grid != null)
{
GridItem[] footerItems = grid.MasterTableView.GetItems(GridItemType.Footer);
if (footerItems.Count() == 1)
{
GridTFoot foot = footerItems[0].Parent.Controls[0].Parent as GridTFoot;
for (int i = 0; i < foot.Controls.Count; i++)
{
GridFooterItem item = foot.Controls[i] as GridFooterItem;
if(item != null)
{
lastFooterPos = i;
break;
}
}
GridFooterItem existingFooter = foot.Controls[lastFooterPos] as GridFooterItem;
GridFooterItem newFooterItem = new GridFooterItem(grid.MasterTableView, 0, 0);
foreach(TableCell fc in existingFooter.Cells)
{
TableCell newFooterCell = new TableCell();
newFooterCell.Text = "allo";
newFooterItem.Cells.Add(newFooterCell);
}
foot.Controls.AddAt(lastFooterPos + 1, newFooterItem);
}
}
}
当然,如果您需要更高的精度,请询问。感谢您的帮助。