gpt4 book ai didi

c# - Telerik Radgrid : adding another footer row

转载 作者:行者123 更新时间:2023-11-30 17:54:55 25 4
gpt4 key购买 nike

我需要向我的 RadGrid 实例添加多个页脚行;但是,目前我只想添加第二个。我目前只有一个页脚行,它可以完美地工作和显示,以供记录。

我找到了 the following relevant question在 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);
}
}
}

当然,如果您需要更高的精度,请直接询问。感谢您的帮助。

最佳答案

在对 Telerik 文档进行一些搜索后,我相当确定这不仅是可能的。在 this question ,例如,Telerik 管理员明确指出“RadGrid 是数据绑定(bind)控件,其项目是根据其数据源中的记录创建的,并显示数据源数据。因此,为了在网格中添加新行,您需要在其数据源中添加新记录并重新绑定(bind)网格。"

因此,为了解决我的问题,我决定删除网格上的页脚并在下方添加一个全新的网格,我将其绑定(bind)到虚拟 DataTable 我将通过我的 Page_Load 事件处理程序中的代码创建。这些值将通过 Javascript 在客户端确定,或者简单地注入(inject)到该虚拟表的行中。

如果有人找到更优雅的解决方案,我仍然有兴趣了解它!不过现在,工作必须向前推进。

关于c# - Telerik Radgrid : adding another footer row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com