Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Justin Grimm 56 posts 138 karma points
    Feb 19, 2013 @ 21:40
    Justin Grimm
    0

    Gridview refresh issues with Umbraco nodes

    I have a fairly straight forward Gridview which pulls in a set of Umbraco nodes. I am binding it on page load.

    My issue comes up on the RowCommand to remove a program(node). The code to remove executes fine. The program(node) gets removed from Umbraco. Yet, no matter what I try, I can't get the GridView to refresh properly. The removed entry is still available. Only a hard browser refresh clears it.

    A databind after the processing was not cutting it. A redirect back to the page was not either. I've tried a permanentRedirect, which works sometimes, but not all.

    <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);
        }
    }

Please Sign in or register to post replies

Write your reply to:

Draft