The Orbit Notebook Software Architecture, Development and Design Thoughts


ASP.NET Repeater – Get A Handle On Your Row

When it comes to the ASP.NET Repeater, I'm coming to find that there are twenty ways to "skin a cat", when it comes to getting a handle on the data and controls within the Repeater.  After writing entirely too much code and eventually finding a much easier way to handle this, I decided to pop a post.

Now, if you've worked with the Repeater for a while, you're familiar with the ItemDataBound event, and how you can get a handle on your controls by calling FindControl() to get a (boxed) instance of your control with which you may then set values, styles, etc.

But, what if you're handling an event of another control that's within your Repeater?  How, then can you get an instance of the Repeater -- or better yet, how can you get a handle on a different control in that row?  NamingContainer is how - it will give you the row that the current event call fired from.

Take this method, for example.  It's the SelectedIndexChanged event for a dropdownlist that's inside of my Repeater.  Not a big deal, but I want to update a label that's in the same row, but in a different column of my repeater.  Here's how it's done:


Comments (2) Trackbacks (0)
  1. Just what I was looking for! Thanks!

  2. This helped me get a handle on my row ;)

Leave a comment

No trackbacks yet.