The Eric Wroolie Blog

Overpass Experiences

  • Blog
  • Videos
  • Overpass Apps

Powered by Overpass Apps

Maintaining Treeview State in Asp.Net 2 with a Sitemap

June 29, 2007 by wroolie 2 Comments

For a couple of days, I was looking around for a way to expand a treeview menu to the node you are currently on. On a site with nodes that go several levels deep, it is a pain to have to open all the nodes every time a postback occurs.

I found code samples online and followed so many goosechases. Some people put a marker in the session to let them know where their node was. Others tried to do some clever javascript which didn’t seem to work for me. It seems to be some code that is heavily in demand.

Finally, I found a blog post by Walt Ritscher which helped me get what I wanted in a few lines of code. It doesn’t maintain the state of all open and closed nodes on the tree, but it does open the tree to the node with the URL of the page you are on. It took me so long to find his blog post from last year, that I thought I would add another link here:

http://waltritscher.com/blog/ramblings/archive/2006/05/18/843.aspx

His examples are in VB.Net, but a conversion to c# is not difficult. Here are my code examples:

In the .aspx page:

<asp:TreeView ID=”TreeView1″ ExpandDepth=”0″ OnTreeNodeDataBound=”treeMainMenu_TreeNodeDataBound” PopulateNodesFromClient=”false” NodeWrap=”false” HoverNodeStyle-ForeColor=”green” HoverNodeStyle-Font-Underline=”true” NodeIndent=”10″ Height=”100%” runat=”server” DataSourceID=”SiteMapDataSource1″>

</asp:TreeView>

Notice the “OnTreeNodeDataBound” and “PopulateNodesFromClient” attributes.

In the code behind:

protected void treeMainMenu_TreeNodeDataBound (

Object sender,

System.Web.UI.WebControls.TreeNodeEventArgs e )

{

if (Request.Url.PathAndQuery == e.Node.NavigateUrl) {

e.Node.ExpandAll();

}

if (e.Node.NavigateUrl == “”) {

e.Node.SelectAction = TreeNodeSelectAction.Expand;

}

}

Anyway, thanks to Walt for his blog post. I looked over some other posts in his blog and found it very interested. You might want to have a look too.

Filed Under: C# Coding, Software Dev & Productivity

Live Earth on 7-7-07

June 27, 2007 by wroolie Leave a Comment

This is going to be a summer of music for me. Just weeks after successfully booking tickets to see Prince in London (they sold out after 30 minutes), we also came up in the lottery to see Live Earth at Wembley. It’s a good cause and I’m really excited about seeing the show.

Just a few more weeks. . .

Filed Under: Miscellaneous Rants

Driving Test Imposters

June 23, 2007 by wroolie Leave a Comment

There’s a story in the news today about the growing problem of imposters sitting practical driving tests. Apparently, it’s possible to hire a look-alike to sit the test for you for just £500.

You can read the article here: http://news.bbc.co.uk/1/hi/uk/6231892.stm

When I came to England, I found the driving test very difficult to pass. I ended up taking it seven times over two years (and I had been driving for over ten years in the States). Each time I failed, the examiner would tell me how very close I was, “but sorry, you didn’t pass.” When I did pass the test, I got a license that doesn’t expire until I’m 70. No more tests. Even if we have flying cars in the year 2042, I won’t mind because my license will still be valid. Even in the States, you have to renew with a written exam every five years or so, but not here.

Now that I spend a lot of time riding around on a motorcycle, I see how drivers rarely look when they change lanes or signal when they enter roundabouts. They’ve established bad habits since they earned their license 20 or 30 or 50 years ago. It’s dangerous.

But, when road accident levels get too high, everyone jumps to the same conclusion—our tests are not difficult enough. They increase the difficulty. When I took the test in my late twenties, everyone said to me “I passed when I was 17, but it wasn’t so difficult then. I could never pass today.” Between the time I took my theory test for cars 6 years ago and the time I took the theory test for motorcycles two months ago, the DSA had attached an additional requirement—The Hazard Safety test. If you have a license already, you don’t have to take this test.

The roads are getting too dangerous so we take it out on 17 year-old kids who’ve never driven before by making sure they take their driving test over and over again. A 65 year-old man who took his test in the early 60’s if far more dangerous, I think. He’s the guy I worry about when riding my motorcycle.

No wonder people hire imposters to take their tests. I wish I knew about this scheme a few years ago.

Filed Under: Bumblings

  • « Previous Page
  • 1
  • …
  • 83
  • 84
  • 85
  • 86
  • 87
  • …
  • 112
  • Next Page »

Recent Posts

  • The Last Human Developer
  • My Gig and the Imposter Syndrome
  • Getting Picked Last for Teams in PE
  • One Little Growth Opportunity at a Time
  • I’m sorry if I look like I know what I’m doing