2

I'm using an ASP.NET TreeView on a page with a custom XmlDataSource. When the user clicks on a node of the tree, a DetailsView pops up and edits a bunch of things about the underlying object. All this works properly, and the underlying object gets updated in my background object-management classes. However, my TreeView just isn't updating the display. Either immediately (which I would like it to), or on full page re-load (which is the minimal useful level I need it to be at). Am I subclassing XmlDataSource poorly? I really don't know. Can anyone point me in a good direction?

The markup looks about like this (chaff removed):

<data:DefinitionDataSource runat="server" ID="DefinitionTreeSource" RootDefinitionID="uri:1"></data:DefinitionDataSource>
<asp:TreeView ID="TreeView" runat="server" DataSourceID="DefinitionTreeSource">
    <DataBindings>
        <asp:TreeNodeBinding DataMember="definition" TextField="name" ValueField="id"  />
    </DataBindings>
</asp:TreeView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    DataKeyNames="Id" DataSourceID="DefinitionSource" DefaultMode="Edit">
    <Fields>
        <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-Wrap="false" SortExpression="Name" />
        <asp:CommandField ShowCancelButton="False" ShowInsertButton="True" ShowEditButton="True"
            ButtonType="Button" />
    </Fields>
</asp:DetailsView>

And the DefinitionTreeSource code looks like this:

public class DefinitionDataSource : XmlDataSource
{
    public string RootDefinitionID
    {
        get
        {
            if (ViewState["RootDefinitionID"] != null)
                return ViewState["RootDefinitionID"] as String;
            return null;
        }
        set
        {
            if (!Object.Equals(ViewState["RootDefinitionID"], value))
            {
                ViewState["RootDefinitionID"] = value;
                DataBind(); 
            }
        }
    }

    public DefinitionDataSource() { }

    public override void DataBind()
    {
        base.DataBind();
        setData();
    }

    private void setData()
    {
        String defXML = "<?xml version=\"1.0\" ?>";
        Test.Management.TestManager.Definition root =
            Test.Management.TestManager.Definition.GetDefinitionById(RootDefinitionID);
        if (root != null)
            this.Data = defXML + root.ToXMLString();
        else
            this.Data = defXML + "<definition id=\"null\" name=\"Set Root Node\" />";
    }
}

}

skink
  • 5,133
  • 6
  • 37
  • 58
Brendan
  • 21
  • 3
  • What does your page_load look like? – Keith Adler Apr 05 '10 at 20:09
  • Nothing in it at the moment. Eventually i'll put some styling tweaks in there (tree.Font.Name, tree.ShowLines, etc) but right now the codebehind contains only empty functions. – Brendan Apr 05 '10 at 20:17
  • If i disable caching in the datasource, it will at least show changes to node names on a full page reload. It doesn't, however, show the changes when the detailsview goes through an update. – Brendan Apr 05 '10 at 20:36

1 Answers1

0

Alright well it seems that databinding just doesn't work quite how i thought it did.

My solution was to tie in to the OnUpdate and OnInsert events for my detailsview data source - when an item is updated in a way that will change the tree i call DataBind explicitly on the treeview's data source. It seems like there must be a cleaner way but i can't find it.

Brendan
  • 21
  • 3