Type safer databinding in legacy asp.net forms projects

22. februari 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 7-9-2013 20:53:57 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 7-9-2013 20:57:05 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 7-9-2013 22:39:55 United States #
Cathern Husseini

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

Gretta Madlock 7-9-2013 22:45:24 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 12-9-2013 01:04:37 United States #
Maxwell Byrne

This is not

visit us at differenthaircolorss 15-9-2013 13:43:51 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 30-9-2013 20:02:18 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 4-10-2013 03:39:19 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 5-10-2013 01:56:56 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 5-10-2013 19:40:38 United States #
Handmade Jewelry

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

Handmade Jewelry 8-10-2013 03:06:56 United States #
Handmade Jewelry

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

Oswietlenie 12-10-2013 16:36:17 United States #
Oswietlenie

Very nice blog

Copper Jewelry 14-10-2013 03:08:00 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 19-10-2013 00:34:25 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 30-10-2013 08:45:42 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 30-10-2013 09:19:47 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 2-11-2013 01:14:15 United States #
Handmade Jewelry

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

Handmade Jewelry 2-11-2013 05:46:36 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 2-11-2013 22:25:39 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 3-11-2013 01:24:21 United States #
Bernie Apodoca

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

Handmade Jewelry 3-11-2013 01:40:40 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 3-11-2013 03:55:14 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 3-11-2013 19:40:44 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 3-11-2013 21:41:33 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 7-11-2013 21:01:09 United States #
Local Video Takeoff Download

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

Micheal Calloway 12-11-2013 05:54:49 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 12-11-2013 08:17:24 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 20-11-2013 22:34:07 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 26-11-2013 21:02:16 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 4-12-2013 23:03:33 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 6-12-2013 08:56:06 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 20-12-2013 03:12:07 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 31-12-2013 03:05:24 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 01:37:09 United States #
Kevin Blanche

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

austin personal injury 1-1-2014 20:44:56 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; 2-1-2014 05:40:04 United States #
Result: chosen nickname &quot;mqgimd7&quot;; success; BB-code not working;

> Because ultimately I am the one paying for it.

site 8-1-2014 02:16:11 United States #
site

Unforgettable night is alaways gauranteed here do not hesitate to visit

recommended you read 30-1-2014 22:39:15 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 6-2-2014 18:10:31 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 7-2-2014 11:59:12 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 29-6-2014 19:03:57 United States #
Tabitha Tod

Fantastic read! I've bookmarked your site.

Marcos Rzepka 1-7-2014 00:55:41 United States #
Marcos Rzepka

Fantastic website.

Gracie Rothgeb 7-4-2015 10:09:34 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 8-4-2015 20:03:36 United States #
Vernie Lanz

Ana|posicionamiento seo turistico 13-4-2015 22:57:54 United States #
Ana|posicionamiento seo turistico

Gracias por compartir

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

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

Julia Hurla 6-5-2015 18:18:23 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 23-5-2015 05:13:05 United States #
Jan

All materials copied from one more supply

Delores Blide 4-6-2015 00:08:48 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 4-6-2015 00:14:21 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 28-6-2015 12:09:58 United States #
Galen Pandey

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

agau bendita trama 5-8-2015 23:51:35 United States #
agau bendita trama