Monday, February 14, 2005

Another thing that went 'click' today...

Although I've been using databinding expressions (the ones that are enclosed by '<%#...%>') in ASP.NET applications for a bit, I never really go how useful they are.

Now normally, I'll sling a repeater onto a page, and put in databinding expressions to populate bits and bobs in the ItemTemplate, like so:

<asp:label runat="server" text='<%# container.dataitem("TheValue") %>' />

But I didn't really realise until today that I could bind anything to anything the same way. The thing that really brought it home today was when I was thinking of having a repeater that contained a UserControl in the ItemTemplate. My UserControl has a public property, 'Item', that was a class that had a bunch of properties that were displayed in the control. I wanted to bind the repeater to an array of said classes.

What you can do in the ItemTemplate, using databinding expressions was this:
<SB:ItemDisplayer runat="server" item='<%# Container.Dataitem() %>' />

Isn't that clever? Well, I though so, anyway. It's one of those things that makes perfect sense when you look at it, but it had never really occurred to me that you could do it that way.

Just wanted to share.

No comments: