【问题标题】:Nested RadGrid in edit mode has unchanged values编辑模式下的嵌套 RadGrid 具有不变的值
【发布时间】:2014-09-04 13:18:38
【问题描述】:

我最近想出了如何随时引用嵌套的 RadGrid 控件,例如在 my answer here 中。

但是,我的主网格和嵌套网格处于编辑模式,并且嵌套网格中的任何新值在回发期间都不存在。如果我编辑任何列中的值,然后单击我的按钮以触发回发,当我访问嵌套的 RadGrid 时,它的值不变(新值与旧值相同)。

aspx(不包括结束标签和客户端JavaScript方法定义和其他随机设置):

<telerik:RadGrid ID="RadGrid1" runat="server" HeaderStyle-Width="675px" Width="675px" Height="359px" PageSize="10" GridLines="None" AccessKey="0" Skin="Office2007"  ImagesPath="~/Skins/Office2007/Grid/Images" AllowFilteringByColumn="false" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" OnEditCommand="RadGrid1_EditCommand" OnCancelCommand="RadGrid1_CancelCommand" OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCommand="RadGrid1_ItemCommand" OnPreRender="RadGrid1_PreRender" >
    <MasterTableView Name="Parent" HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind" DataKeyNames="ID" EditMode="InPlace" >
        <NestedViewTemplate>
            <asp:Panel ID="RadGrid2" runat="server" >
                <telerik:RadGrid ID="rgDetailItems" runat="server" Width="1675px" AutoGenerateColumns="false" AllowPaging="false" ShowFooter="true"
                OnEditCommand="rgDetailItems_EditCommand" OnCancelCommand="rgDetailItems_CancelCommand" OnUpdateCommand="rgDetailItems_UpdateCommand" 
                OnNeedDataSource="rgDetailItems_NeedDataSource" OnItemDataBound="rgDetailItems_ItemDataBound" >
                    <MasterTableView EditMode="InPlace">
                        <Columns>
                            <telerik:GridBoundColumn HeaderText="Amount" DataField="DtlTransAmount" UniqueName="DtlTransAmount" SortExpression="DtlTransAmount"
                            HeaderStyle-Width="20px" ItemStyle-Width="20px" FilterControlWidth="20px" DataFormatString="{0:$0.00}"/>

cs:

var items = ((RadGrid1.MasterTableView.Items[0].ChildItem as GridNestedViewItem)
    .FindControl("RadGrid2") as RadGrid).EditItems;
foreach (GridEditableItem editItem in items)
{
    Hashtable newValues = new Hashtable();
    editItem.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
    foreach (DictionaryEntry de in newValues)
    {
        string valOld = (editItem.SavedOldValues[de.Key] as string) ?? "";
        string valNew = (newValues[de.Key] as string) ?? "";

        // valOld always equals valNew!
    }
}

是否有不同的方法来获取嵌套的 RadGrid 或其项目,以便显示其编辑的值?

【问题讨论】:

  • 能否提供您的aspx页面代码?
  • 为网格发布了 aspx 标记。我删除了像ClientSettingsEditItemStyle 这样的额外信息。
  • 我得到了@JayeshGoyani 的答案。感谢您查看此内容。

标签: c# asp.net telerik radgrid


【解决方案1】:

这个问题的原因是第0个索引处的项目不是整个网格,它是网格的当前行。我没有看到任何新值的原因是因为我只检查行集合中的第一行 (Items[0])。

解决方案是遍历主 RadGrid 中的每一行,并为每一行 (Items[i]) 获取嵌套的 RadGrid 及其行:

for (int i = 0; i < RadGrid1.EditItems.Count; i++)
{
    var items = ((RadGrid1.MasterTableView.Items[i].ChildItem as GridNestedViewItem)
        .FindControl("RadGrid2") as RadGrid).EditItems;
    foreach (GridEditableItem editItem in items)
    {
        Hashtable newValues = new Hashtable();
        editItem.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
        foreach (DictionaryEntry de in newValues)
        {
            string valOld = (editItem.SavedOldValues[de.Key] as string) ?? "";
            string valNew = (newValues[de.Key] as string) ?? "";

            // valNew contains new values if they were changed by the user!
        }
    }
}

【讨论】:

  • 嗨@DanM7,您能否编辑您的答案,因为我错误地否决了它。现在它被锁定了,我无法恢复它。如果您编辑答案,它允许我投票。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-17
相关资源
最近更新 更多