The best approach would be be to add the Edit link in the GridView
rather than in the TreeView. Adding values to the query string is easy
inside the GridView, just add a HyperLinkField and populate the
DataNavigateURLFields and DataNavigateUrlFormatString. However, if you
are stuck using a TreeView to navigate to the Edit Page, you have to
update the URL programatically (someone correct me if I'm wrong about
this). Here's a form with a GridView control and a TreeView.
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView" runat="server"
DataSourceID="SiteMapDataSource">
</asp:TreeView>
<asp:GridView ID="GridView" runat="server"
DataSourceID="SqlDataSource"
OnSelectedIndexChanged="GridView_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
<SelectedRowStyle BackColor="#FFFFC0" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings

ubsConnectionString
%>"
SelectCommand="SELECT [ord_num], [ord_date], [qty] FROM
[sales]">
</asp:SqlDataSource>
</div>
<asp:SiteMapDataSource ID="SiteMapDataSource" runat="server" />
</form>
And here's the Web.Sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="
http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home">
<siteMapNode url="~/EditOrder.aspx" title="Edit Order" />
</siteMapNode>
</siteMap>
To set the querystring on the EditOrder link update it when the
selected item on the grid changes:
protected void GridView_SelectedIndexChanged(object source, EventArgs
e)
{
GridViewRow row = GridView.SelectedRow;
string order_number = row.Cells[1].Text;
TreeNode tn = TreeView.FindNode(Server.HtmlEncode("Home/Edit
Order"));
tn.NavigateUrl = string.Format("~/EditOrder.aspx?ord_num={0}",
order_number);
}
You can improve on the code to get the order_number and find the
TreeNode, but the key is updating the NavigateURL each time the
selected item changes. It's a little ugly, but if you need to use a
TreeView bound to a sitemap file it may be your only option.
-Carl