By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Gridview Selection

P: n/a
Is it possible to select an item on a gridview by clicking on it and
then being able to click a link for example that says EditOrder in a
treeview and have the EditOrder page open up viewing what you selected
in the gridview? My EditOrder link is in a sitemap so I don't know if
it is possible becuase you would almost have to pass a variable to the
sitemap. What would be the easiest way to accomplish it?

Feb 21 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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">
<asp:TreeView ID="TreeView" runat="server"

<asp:GridView ID="GridView" runat="server"
OnSelectedIndexChanged="GridView_SelectedIndexChan ged">
<asp:CommandField ShowSelectButton="True" />
<SelectedRowStyle BackColor="#FFFFC0" />

<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:pubsConnectionString
SelectCommand="SELECT [ord_num], [ord_date], [qty] FROM
<asp:SiteMapDataSource ID="SiteMapDataSource" runat="server" />

And here's the Web.Sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="" >
<siteMapNode url="~/Default.aspx" title="Home">
<siteMapNode url="~/EditOrder.aspx" title="Edit Order" />

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
GridViewRow row = GridView.SelectedRow;
string order_number = row.Cells[1].Text;

TreeNode tn = TreeView.FindNode(Server.HtmlEncode("Home/Edit
tn.NavigateUrl = string.Format("~/EditOrder.aspx?ord_num={0}",

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.


Feb 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.