views:

54

answers:

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. Yay! 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? Thanks!

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\" />";
    }
}

}

A: 

can you post some of your code?

Allan Palmer
FYI: You should add this as a comment to the question rather than as an answer.
CAbbott
Can and did. :)
Brendan
A: 

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