1

我有一个相当直接的 Gridview,它引入了一组 Umbraco 节点。我在页面加载时绑定它。

我的问题出现在 RowCommand 上以删除程序(节点)。要删除的代码执行得很好。程序(节点)从 Umbraco 中删除。然而,无论我尝试什么,我都无法让 GridView 正确刷新。删除的条目仍然可用。只有硬浏览器刷新才能清除它。

处理后的数据绑定没有切割它。重定向回页面也不是。我尝试了一个永久重定向,它有时有效,但不是全部。

<asp:GridView ID="gvPrograms" runat="server" CssClass="styledTable"
        AllowPaging="true" 
        PageSize="5"
        AutoGenerateColumns="false"
        OnPageIndexChanging="gvPrograms_PageIndexChanging"
        onrowcommand="gvPrograms_RowCommand" 
        onrowdatabound="gvPrograms_RowDataBound">

       <rowstyle backcolor="White"  
       forecolor="#006296"
       font-italic="false"/>

      <alternatingrowstyle backcolor="#dbeef9"  
      forecolor="#006296"
      font-italic="false"/>

        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Program Name" />
            <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:Label ID="lblProgramDate" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit" runat="server" Text="Edit"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="lnkRemove" runat="server" Text="Remove"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

 protected void gvPrograms_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Edit Program")
    {
        PopulateProgram(e.CommandArgument.ToString());
        displayPanels(pnlAddProgram);
        hdrEdit.InnerText = "Edit Program";
    }
    else if (e.CommandName == "Remove Program")
    {
        int id = Int32.Parse(e.CommandArgument.ToString());

        //remove node from umbraco
        Document d = new Document(id);
        //umbraco.library.UnPublishSingleNode(id);
        d.delete();
        umbraco.library.UpdateDocumentCache(d.Id);
        umbraco.content.Instance.RefreshContentFromDatabaseAsync();
        umbraco.library.RefreshContent();

        lblMsg.Text = "The program has been successfully removed!";
        lblMsg.Visible = true;

        Response.RedirectPermanent("/chapter-tools/chapter-management-center/chapter-content-admin/programs-list.aspx");
        //BindData(programsNodeID);
    }
}

private void BindData(string programsNodeID)
{
    DataTable dt = new DataTable();
    Node programsNode = new Node(Convert.ToInt32(programsNodeID));
    dt = programsNode.ChildrenAsTable();

    gvPrograms.DataSource = dt;
    gvPrograms.DataBind();

    if (gvPrograms.Rows.Count > 0)
        lblNone.Visible = false;
    else
        lblNone.Visible = true;
}
4

1 回答 1

0

正如Munkimagik 的技术博客所建议的那样,您可以在删除之前先尝试取消发布该节点。

Document d = new Document(id);

if(d.Published)
{
    d.UnPublish();
    umbraco.library.UnPublishSingleNode(d.Id);
}

d.delete();
umbraco.library.UpdateDocumentCache(d.Id);
于 2013-02-19T18:03:05.303 回答