Strongly typed asp.net data binding improved version

Source: Internet
Author: User
Keywords Settlement type conversion two so to force
Tags .mall .net applied asp asp.net code data force

Related articles: teach you 30 seconds to build strong type ASP.net data binding, strongly typed ASP.net data binding improved version 2nd

Read Dragonpig wrote "teach you 30 seconds to build strong type ASP.net data binding," a bright, is really too much power, the original can also be data binding.

Immediately a small try, and made some improvements, has now been applied to the news column in the home. Let's share some of the improvements.

With the traditional asp.net data-binding approach, there are two places that have been uncomfortable:

1 lack of intelligent perception;

2 Force type conversion.

Let's take a look at the traditional ASP.net data binding:

Look at the above ToString (), (DateTime) ...

Dragonpig's strongly typed binding mentality already contains a way to solve both of these problems, but in the code he shows, the first problem (IntelliSense) is ignored, but the second problem (coercion type conversion) is omitted, and the original code is as follows:

Protected virtual Object exphelper<tentity, tresult> (func<tentity, tresult> Func)
{
var itm = Getdataitem ();
return func ((tentity) ITM);
}
Protected Object Stu<tresult> (Func<student, tresult> Func)
{
Return exphelper<student, Tresult> (func);
}

I found in the use of forced type conversion, a bit uncomfortable, research, the original is the trouble of object, as long as the above code two object to TResult, the problem is solved.

In addition, I changed the Stu method name to Eval, which feels more friendly.

Code on:

Protected virtual TREsult exphelper<tentity, tresult> (func<tentity, tresult> Func)
{
var item = base. Getdataitem ();
return func ((tentity) item);
}
Protected TResult eval<tresult> (Func<newsinfo, tresult> Func)
{
Return Exphelper<newsinfo, Tresult> (func);
}

The days after strong type asp.net data binding are wonderful ...

Thank dragonpig! Your sharing is too good!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.