嵌套网格编辑;不起作用

本文关键字:不起作用 编辑 网格 嵌套 | 更新日期: 2023-09-27 18:24:27

我遇到了这个问题,因为我在嵌套网格可编辑的网格中有网格。我无法进行编辑。更复杂的是,嵌套网格位于模式弹出扩展程序中。

它工作到我点击编辑按钮的地步。然后EmptyDataText属性将显示消息。如果我第二次点击它,网格在编辑模式下打开,但更新/取消按钮不起作用。单击时的取消按钮显示EmptyDataText属性。

另一个问题是,这个嵌套网格没有使用对象数据源,所以我将不得不在代码文件中进行所有更新和删除。现在也不确定该怎么做。

我想要一些关于如何纠正这一点的建议。这是代码:

<asp:GridView ID="gvForum" runat="server" DataSourceID="odsForumApproval" DataKeyNames="id" Width="200px"
RepeatColumns="1" DataKeyField="id" CssClass="gridview"
AutoGenerateColumns="False" GridLines="None" OnSelectedIndexChanged="_OnCommand">
<AlternatingRowStyle CssClass="altbgcolor"  />
<Columns>
    <asp:TemplateField >
        <ItemTemplate>
            <asp:Label runat="server" ID="lblTitle" Text='<%# Bind("Title") %>' />
            <asp:Panel id="div" runat="server" align="center" class="confirm" style="display:none"  >
                <asp:GridView runat="server" ID="gvForumDetail" AutoGenerateColumns="False" DataKeyNames="id"
                    AllowPaging='true' CssClass="gridview" 
                    AllowSorting="true" PageSize="5" CellPadding="5" OnRowEditing="gvForumDetail_OnRowEditing"
                    OnRowCancelingEdit="gvForumDetail_CancelRecord"  >
                    <AlternatingRowStyle CssClass="altbgcolor" />
                    <RowStyle VerticalAlign="Top" HorizontalAlign="Left" />
                    <HeaderStyle  CssClass="greenbar" ForeColor="White" /> <Columns>
                        <asp:BoundField DataField="id" ReadOnly="true" Visible="false" />
                        <asp:TemplateField HeaderText="Title">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblTraining" Text='<%# Bind("title") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox runat="server" ID="txtTraining" Text='<%# Bind("title") %>' />
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Post Message">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblCompletionDate" Width="250"  Text='<%# Bind("description") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox runat="server" ID="txtDescription" Text='<%# Bind("description") %>' TextMode="MultiLine" Rows="5" Width="250" />
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Posted By">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblRecurence" Text='<%# Bind("MemberName") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Posted Date">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblNotes" Text='<%# Eval("itemdate", "{0:d}") %>'  />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:CheckBox runat="server" ID="cbxApproved" Text='<%# Bind("approved") %>' />
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowCancelButton="true" ShowEditButton="true" ShowDeleteButton="true" />
                    </Columns>
                </asp:GridView>
                <br />
                <Club:RolloverLink ID="btnClose" runat="server" Text="Close" />
            </asp:Panel>
            <ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                TargetControlID="lblTitle"
                PopupControlID="div"
                CancelControlID="btnClose"
                BackgroundCssClass="modalBackground" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:CommandField ShowSelectButton="True"  />
</Columns>

代码背后:

public void _OnCommand(object sender, EventArgs e)
{
    ObjectDataSource ods = new ObjectDataSource();
    ods.ID = "ods_ForumDetail";
    ods.EnableViewState = true;
    ods.TypeName = "ForumApproval";
    ods.SelectMethod = "GetForumById";
    string id = "";
    int rowIndex = gvForum.SelectedIndex;
    id = gvForum.DataKeys[rowIndex].Value.ToString();
    ods.SelectParameters.Add("id", System.TypeCode.Int32, id);
    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();
    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
    gvForumDetail.DataSource = ods;
    gvForumDetail.DataBind();
}
protected void gvForumDetail_OnRowEditing(Object sender, GridViewEditEventArgs e)
{
    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();
    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
    gvForumDetail.EditIndex = e.NewEditIndex;
    gvForumDetail.DataBind();
}
protected void gvForumDetail_CancelRecord(object sender, GridViewCancelEditEventArgs e)
{
    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();
    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
    gvForumDetail.EditIndex = -1;
    gvForumDetail.DataBind();
}

嵌套网格编辑;不起作用

我将尝试回答您的部分问题,更新和删除代码。您需要利用"onrowcommand"作为内部网格视图(onrowcommand)。