Monday, January 23, 2006

More Nested Repeater Control

I spent some time on Saturday working on my new navigation system.  The one the required the use of Nested Repeater Controls.  While working with them a little more I found it rather challenging to write to a Literal control that was in the Header Template of the nested repeater control.  The problem I was having was figuring out how/when the ItemDataBound event got fired.  The typical place to put the event declaration is in the InitializeComponent method but this would cause a runtime error as the nested Repeater wasn't in scope just yet.

I found through some frustrating trial and error that if you put the event declaration in the main repeaters ItemDataBound event and set it before you bound the nested repeater, the event would fire correctly.

Here is the code:

   1:      private void repMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
   2:          {
   3:              repSubMenu.ItemDataBound += new RepeaterItemEventHandler(repSubMenu_ItemDataBound);
   4:              repSubMenu.DataSource = page.SelectAllWSectionIDLogic();;
   5:              repSubMenu.DataBind();
   6:          }
   7:   
   8:          private void repSubMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
   9:          {
  10:              
  11:              if (e.Item.ItemType == ListItemType.Header)
  12:              {
  13:                  litSpan = (Literal)e.Item.FindControl("litSpan");
  14:                  litSpan.Text = "<span class=\"submenu\" id=\"sub" + _count.ToString() + "\">";
  15:              }
  16:          }

Oh and if you want to see the finished Navigation you can see it here.  Used two nested Repeaters, LLBLGen Data code generation and some expanding javascript.  I am waiting on the go ahead to drop that control into the site.
Sunday, June 24, 2007 2:28:22 AM (Eastern Daylight Time, UTC-04:00)
You have cool guestbook, interesting information... Keep it UP. excellent site i really like your stuff. These sites media portal is also great! ...
Thursday, July 05, 2007 4:47:12 AM (Eastern Daylight Time, UTC-04:00)
Sorry, the link is broken

http://www.csee.net/navmenu.aspx

Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /NavMenu.aspx


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):

Blog Posts by:

Currently Viewable:

My Twitter Updates

View Twitter Page