Setting TreeViewNode to selected on PageLoad
<p>I have a tree view that I'm dynamically loading on the PageLoad event. Here is my tree view and data source:</p>

<pre><code>&lt;asp:TreeView ID="tv" runat="server" DataSourceID="xds"
    SelectedNodeStyle-ForeColor="Red" NodeStyle-ForeColor="Black"&gt;   
    &lt;DataBindings&gt;
        &lt;asp:TreeNodeBinding DataMember="Node"
            ValueField="Id" TextField="Title"  /&gt;
    &lt;/DataBindings&gt;
&lt;/asp:TreeView&gt;
&lt;asp:XmlDataSource ID="xds" runat="server" EnableCaching="false" /&gt;
</code></pre>

<p>This is the code I run on PageLoad </p>

<pre><code>StringBuilder sb = new StringBuilder();
XmlWriter xw = XmlWriter.Create(sb);

WriteTreeViewXml(xw);
xw.Flush();
xw.Close();

xds.Data = sb.ToString();
xds.DataBind();

tv.Nodes[0].Selected = true;  // error here
</code></pre>

<p>This works fine, the tree view gets loaded correctly. Now I'm trying to add styling to the SelectedNode. This works when I click on a specific node, but the root node isn't styled when the page loads. So I'm trying to set the root node to selected on PageLoad</p>

<p>I get this error when I try to set the root node as selected:</p>

<blockquote>
  <p><strong>Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index</strong></p>
</blockquote>

<p>For some reason the tree view is empty after I bind the data source.</p>

<p>Does anyone know how I can do this?</p>
