locked
get the url and find node based on the url and navigateurl of that node RRS feed

  • Question

  • User-1614911347 posted

    hello. i just wanna know if there is any way that i can take the page current url ( ex. hhtp://www.mysite.com/expo/something.aspx?IDsomething=1 ) and then compare it to the nodes navigateurl in a  treeview so i can somehow expand the node acording after navigation? the treeview is db generated - no xml and no sitemap - and it's placed on a masterpage.

    tnx

    if anyone wanna look at the code this is it:

    the treeview:

    <asp:TreeView id="LinksTreeView" EnableClientScript="true" OnTreeNodePopulate="PopulateNode" runat="server"

    populatenodesfromclient="False" NodeWrap="True" ExpandDepth="1" skinid="menuSkin">

     

    <Nodes>

     

    <asp:TreeNode Text="Home" SelectAction="Expand" Value="Home" NavigateUrl="~/Default.aspx" PopulateOnDemand="True"/>

     

    </Nodes>

     

    </asp:TreeView>

    the code behind:

    protected void PopulateNode(Object sender, TreeNodeEventArgs e)

    {

    // Call the appropriate method to populate a node at a particular level.

    switch (e.Node.Depth)

    {

    case 0:

    // Populate the first-level nodes.

    PopulateMenu(e.Node);

    break;

    case 1:

    // Populate the second-level nodes.

    PopulateSomething(e.Node);

    break;

    case 2:

    // Populate the third-level nodes.

    PopulateItemsSomething(e.Node);

    break;

    default:

    // Do nothing.

    break;

    }

    void PopulateMenu(TreeNode node)

    {

    DataSet ResultSet = RunQuery("Select Something, Something, Url, From Menu");

    if (ResultSet.Tables.Count > 0)

    {

    foreach (DataRow row in ResultSet.Tables[0].Rows)

    {

    TreeNode NewNode = new TreeNode(row["Something"].ToString(), row["IDSomething"].ToString()); NewNode.PopulateOnDemand = true;

    NewNode.NavigateUrl = row["Url"].ToString();

    node.SelectAction = TreeNodeSelectAction.Select;

    node.ChildNodes.Add(NewNode);

    }

    }

     

    void PopulateSomething(TreeNode node)

    {

    // Query for the products of the current category. These are the values

    // for the third-level nodes.

    DataSet ResultSet = RunQuery("Select Something, IDSomething, IDMenu From Something Where IDMenu=" + node.Value);

    // Create the third-level nodes.

    if (ResultSet.Tables.Count > 0)

    {

    // Iterate through and create a new node for each row in the query results.

    // Notice that the query results are stored in the table of the DataSet.

    foreach (DataRow row in ResultSet.Tables[0].Rows)

    {

    // Create the new node.

    string colectiiValue = "c" + row["IDSomething"].ToString();

    TreeNode NewNode = new TreeNode(row["Something"].ToString(), colectiiValue);

    NewNode.SelectAction = TreeNodeSelectAction.Select;

    NewNode.PopulateOnDemand = true;

    // Set additional properties for the node.

    NewNode.NavigateUrl = string.Format("ro/Something/Something.aspx" + "?IDSomething=" + row["IDSomething"].ToString());

    // Add the new node to the ChildNodes collection of the parent node.

    node.ChildNodes.Add(NewNode);

    }

    }

    }

    Friday, May 30, 2008 8:23 AM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your code, it seems that the value of treenode comes from your back-end database, and what you want is to compare the url of current request with those values in treeview, right?

    <o:p> </o:p>

    If so, you can try to use HttpContext.Current.Request.Url.ToString() or HttpContext.Current.Request.Url.PathAndQuery to get the url of current request, and finish the comparing logic in a loop against the treenodes collection.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 2, 2008 10:04 PM

All replies

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your code, it seems that the value of treenode comes from your back-end database, and what you want is to compare the url of current request with those values in treeview, right?

    <o:p> </o:p>

    If so, you can try to use HttpContext.Current.Request.Url.ToString() or HttpContext.Current.Request.Url.PathAndQuery to get the url of current request, and finish the comparing logic in a loop against the treenodes collection.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 2, 2008 10:04 PM
  • User-1614911347 posted

    hello and thx for the response. can u give me some example or a link to how do what u said? thx

    Wednesday, June 4, 2008 3:13 AM
  • User-1136466523 posted

    Hi,

    It should be:

       string currenturl = HttpContext.Current.Request.Url.ToString();

            foreach (TreeNode tn in this.TreeView1.Nodes) {

                if (tn.Value.ToLower().Equals(currenturl)) {
                   
                    // Write the logic for expanding the current node ...
                    break;   
                   
                }
            }

    Thanks.

    Wednesday, June 4, 2008 11:49 PM