Type safer databinding in legacy asp.net forms projects

22. February 2013 10:56 by admin in .net, vs2010 vs2012
I love compilers. I love ReSharper. And that's why i hate statements like this:

<%# DataBinder.Eval(Container.DataItem,"FirstName") %>
If I was to change the name of the FirstName property or would try to find all references to this property this would not work! In asp.net 4.5 there is a ItemType property on databinding controls which you can use so the dataitem gets a proper type. See http://brijbhushan.net/2012/07/01/strongly-typed-data-controls-and-modal-binding-in-asp-net-4-5-part-1/ for an explanation about this. Unfortunately not all code is asp.net 4.5 and we can not use this feature everywhere. 

In pre asp.net 4.5 projects we can use a different construct. On the container of the databinding control we expose a type-safe version on the current dataitem like this:
public Person CurrentDataItem
{
get { return (Person) Page.GetDataItem(); }
}
Now in our binding control we can use:
 <%# CurrentDataItem.FirstName %>
No strings involved :) See the attached vs2008 sample project for an example.

TypeSafeBindingExample.zip (27,75 KB)
Lisa Dingie 9/7/2013 8:53:57 PM United States #
Lisa Dingie

Hey very nice blog!! Guy .. Excellent .. Amazing .. I'll bookmark your website and take the feeds also�I am glad to seek out so many helpful information here within the publish, we need work out extra strategies on this regard, thanks for sharing.

Synthia Buddington 9/7/2013 8:57:05 PM United States #
Synthia Buddington

Wow! This can be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Fantastic. I'm also a specialist in this topic so I can understand your effort.

Cathern Husseini 9/7/2013 10:39:55 PM United States #
Cathern Husseini

You are my  intake , I  possess few  web logs and  very sporadically  run out from to post .

Gretta Madlock 9/7/2013 10:45:24 PM United States #
Gretta Madlock

Thanks for the sensible critique. Me and my neighbor were just preparing to do some research on this. We got a grab a book from our local library but I think I learned more clear from this post. I am very glad to see such wonderful information being shared freely out there.

Maxwell Byrne 9/12/2013 1:04:37 AM United States #
Maxwell Byrne

This is not

visit us at differenthaircolorss 9/15/2013 1:43:51 PM United States #
visit us at differenthaircolorss

The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it'll do even better in those areas, but for now it's a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod's strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

Handmade Jewelry 9/30/2013 8:02:18 PM United States #
Handmade Jewelry

Hi there, just became alert to your blog by means of Google, and discovered that it�s truly informative. I'm going to watch out for brussels. I�ll appreciate in the event you continue this in future. Several men and women is going to be benefited from your writing. Cheers!

Copper Jewelry 10/4/2013 3:39:19 AM United States #
Copper Jewelry

Hello� DropshipDragon provides dropping for quality, affordable products direct from China to your customers. Perfect for eBay sellers and website owners alike!�

Handmade Jewelry 10/5/2013 1:56:56 AM United States #
Handmade Jewelry

Were required to give you that almost no remark as a way to thanks a lot yet once again of these spectacular techniques you may have provided in this posting. It is so particularly generous with folks such as you to create unreservedly what the majority of us may possibly have marketed for an book to earn some dough in their own business, primarily since you might have tried it inside the event you wanted. The tactics also acted to be good method to know that everyone�s comparable desire just as my own, personal to figure out completely much more regarding this condition. I�m sure you can find thousands of much more pleasant opportunities up front for many who go by means of your web site post.

Handmade Jewelry 10/5/2013 7:40:38 PM United States #
Handmade Jewelry

I adore  gathering   beneficial    info, this post has got me even far more information! .

Handmade Jewelry 10/8/2013 3:06:56 AM United States #
Handmade Jewelry

I like this weblog it�s a master piece! Glad I discovered this on google.

Oswietlenie 10/12/2013 4:36:17 PM United States #
Oswietlenie

Very nice blog

Copper Jewelry 10/14/2013 3:08:00 AM United States #
Copper Jewelry

What a fantastic post you might have created. I just stopped in to let you know I really enjoyed the read and shall be dropping by from time to time from now on.

Handmade Jewelry 10/19/2013 12:34:25 AM United States #
Handmade Jewelry

In the event you tow a definite caravan nor van movie trailer your entire family pretty soon get exposed to the down sides towards preventing greatest securely region. awnings

Unique Copper Earrings 10/30/2013 8:45:42 AM United States #
Unique Copper Earrings

It's really rare these days to uncover internet sites that give info someone is seeking for. I am glad to see that your site share valued information that can help to many readers. good one and keep writing!

Natalya Niimi 10/30/2013 9:19:47 AM United States #
Natalya Niimi

Thanks for the concepts you've got shared here. Something else I would genuinely like to mention is the fact that laptop memory space house needs normally go up furthermore to other advancements from the technological innovation. As an example, any time new generations of processors are designed through the present-day market, there could be normally a comparable raise through the form cellphone phone calls for of all laptop or computer method procedure memory space plus tough disk place. This truly is simply simply because the software package package deal method operated by basically

Handmade Jewelry 11/2/2013 1:14:15 AM United States #
Handmade Jewelry

For some cause the picture just isn’t loading appropriately, is at this time there an concern?

Handmade Jewelry 11/2/2013 5:46:36 AM United States #
Handmade Jewelry

We stumbled over here coming from a different internet page and thought I might check issues out. I like what I see so now i’m following you. Look forward to exploring your internet page however once more.

Arnold Wenzel 11/2/2013 10:25:39 PM United States #
Arnold Wenzel

Sorry for the huge review, but I'm really loving the new Zune, and hope this, as well as the excellent reviews some other people have written, will help you decide if it's the right choice for you. <A href="http://falak.me">;������</A> <A href="http://falak.me">;�������</A> <BR><A href="http://falak.me">;�����</A> <A href="http://falak.me">;���� �����</A> <A href="http://falak.me">;����� �����</A> <A href="http://falak.me">;����</A>

Bernie Apodoca 11/3/2013 1:24:21 AM United States #
Bernie Apodoca

Excellent read! I've saved your site and I'm including your feed.

Handmade Jewelry 11/3/2013 1:40:40 AM United States #
Handmade Jewelry

Howdy! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?

Handmade Jewelry 11/3/2013 3:55:14 AM United States #
Handmade Jewelry

I’m actually loving the theme/design of your internet website. Do you ever run into any browser compatibility troubles? Quite a few my weblog readers have complained about my website not operating correctly in Explorer but looks fantastic in Opera.  Do you have any solutions to help fix this problem?

Handmade Jewelry 11/3/2013 7:40:44 PM United States #
Handmade Jewelry

Unquestionably believe that which you said. Your favorite justification seemed to be on the web the simplest thing to be aware of. I say to you, I certainly get irked although individuals consider worries that they just don’t know about. You managed to hit the nail upon the top and defined out the entire thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks

Handmade Jewelry 11/3/2013 9:41:33 PM United States #
Handmade Jewelry

Pretty good post. I just stumbled upon your blog and wanted to say that I've truly enjoyed browsing your weblog posts. In any case I’ll be subscribing to your rss feed and I hope you write once more very soon!

Local Video Takeoff Download 11/7/2013 9:01:09 PM United States #
Local Video Takeoff Download

technique i will subscribe to brand new articles you recognize like purchasing these about email

Micheal Calloway 11/12/2013 5:54:49 AM United States #
Micheal Calloway

If I choose to buy an Android, can I use any of the music on my Itunes on my new Android device?

My Favorite 11/12/2013 8:17:24 AM United States #
My Favorite

Hi buddie, I just wanted to share with you that this post was really helpful to me. We were capable of take the tips you actually so kindly shared and put it to use. Your blog content truly worked for me and I want to tell your dedicated subscribers that they may really have some one who has her or his mind right. Many thanks once again for your terrific post. I've truly bookmarked it on my favored internet book-marking site and that i advise everybody else do the exact same.

Ty Hansbury 11/20/2013 10:34:07 PM United States #
Ty Hansbury

When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

had me going 11/26/2013 9:02:16 PM United States #
had me going

As soon as I  discovered  this  web site  I went on reddit to share some of the love with them.

letters from Santa 12/4/2013 11:03:33 PM United States #
letters from Santa

Hi there! Someone in my Myspace group shared this site with us so I came to take a look. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Excellent blog and amazing style and design.

Santa letters 12/6/2013 8:56:06 AM United States #
Santa letters

My spouse and I stumbled over here coming from a different page and thought I should check things out. I like what I see so i am just following you. Look forward to looking at your web page yet again.

ATT UVERSE 12/20/2013 3:12:07 AM United States #
ATT UVERSE

Does your blog have a contact page? I'm having a tough time locating it but, I'd like to shoot you an email. I've got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.

Ronny Shoaff 12/31/2013 3:05:24 AM United States #
Ronny Shoaff

Appreciate the time and energy you put into your site and detailed information you offer. It's a great to come across a blog every once in a while that isn't the same out of date rehashed information.

Kevin Blanche 1/1/2014 1:37:09 AM United States #
Kevin Blanche

Good day I am delighted that I�ve found your webpage

austin personal injury 1/1/2014 8:44:56 PM United States #
austin personal injury

Also take a look at my web site: propecia - uxd.isobarkorea.co.kr/.../index.php My spouse and that i totally appreciate your web site and obtain lots of your post's for being precisely what I'm looking for. Would you offer guest writers to jot down written content for your self? I wouldn't intellect composing a post or elaborating on some of the subjects you produce similar to here. Once more, awesome website!

Result: chosen nickname "mqgimd7"; success; BB-code not working; 1/2/2014 5:40:04 AM United States #
Result: chosen nickname &quot;mqgimd7&quot;; success; BB-code not working;

> Because ultimately I am the one paying for it.

site 1/8/2014 2:16:11 AM United States #
site

Unforgettable night is alaways gauranteed here do not hesitate to visit

recommended you read 1/30/2014 10:39:15 PM United States #
recommended you read

Somebody essentially assist to make significantly articles I might state. That is the very first time I frequented your web page and so far? I amazed with the analysis you made to create this actual publish extraordinary. Magnificent activity!

Aida 2/6/2014 6:10:31 PM United States #
Aida

The information here is first class, I hop I can come back again when I have the time.

world cup qualifying matches today 2/7/2014 11:59:12 AM United States #
world cup qualifying matches today

Hi there, I thought this is possibly as good a place as any to give you a heads up, if I attempt to read your rss feed I get an error: "XML Parsing Error" - that is in Firefox? I hope if it is something on your end that you can update it: I would like to add your rss to FeedDemon. I hope to be able to do that soon, Best Regards, Bell Plankey from Durg-Bhilai Nagar

Tabitha Tod 6/29/2014 7:03:57 PM United States #
Tabitha Tod

Fantastic read! I've bookmarked your site.

Marcos Rzepka 7/1/2014 12:55:41 AM United States #
Marcos Rzepka

Fantastic website.

Gracie Rothgeb 4/7/2015 10:09:34 AM United States #
Gracie Rothgeb

Friendly Software Online - Powerful Software - Here you can find very good tools for Computers with Windows or Mac, Tablets or Phones with Android or IOs.

Vernie Lanz 4/8/2015 8:03:36 PM United States #
Vernie Lanz

Ana|posicionamiento seo turistico 4/13/2015 10:57:54 PM United States #
Ana|posicionamiento seo turistico

Gracias por compartir

Isa Wiesen 5/1/2015 11:16:35 AM United States #
Isa Wiesen

Very interesting details you have remarked, thank you for posting.

Julia Hurla 5/6/2015 6:18:23 PM United States #
Julia Hurla

I really  enjoy  studying on this  site, it  holds   great   articles . "For Brutus is an honourable man So are they all, all honourable men." by William Shakespeare.

Jan 5/23/2015 5:13:05 AM United States #
Jan

All materials copied from one more supply

Delores Blide 6/4/2015 12:08:48 AM United States #
Delores Blide

This issue is like poetry, there is way more to the post than we see here.  That's why I think you should always check many sources before coming to a conclusion.  Keep writing.

Leonor Coburn 6/4/2015 12:14:21 AM United States #
Leonor Coburn

I appreciate all the sound tips.  I've read too much for today so I'm going to simply place the butt of my Vega in my ashtray and burn it go out of its own accord.  Thanks again!

Galen Pandey 6/28/2015 12:09:58 PM United States #
Galen Pandey

Good article. I'm experiencing some of these issues as well..|

agau bendita trama 8/5/2015 11:51:35 PM United States #
agau bendita trama