Common codes for ASP. NET data binding)

Source: Internet
Author: User

ASP. NET data bindingCode

Category: C # & ASP. NET code

Binding with databinder. Eval does not require you to care about the data source (dataread or dataset ). The data type Eval will convert the data object into a string. It does a lot of work on the underlying binding and uses the reflection performance. This is because it is easy to use, but affects data performance. When dataset is bound, dataitem is actually a datarowview (if it is bound to a data reader (dataread), it is an idatarecord .) Therefore, directly converting to datarowview will greatly improve the performance.
Note: 1. Pay attention to the Case sensitivity of Field Names (special attention ). If it is inconsistent with the query, it may be slower than <% # databinder. eval (container. dataitem, "field name") %> in some cases. 2. If you want to further increase the speed, you can use the <% # (system. Data. datarowview) container. dataitem) [0] %> method. But its readability is not high.

// When dataset is used as the data source

// Normal (C #)

<% # (System. Data. datarowview) container. dataitem) ["title"] %>

// Bind the Date Field Format String

<% # Convert. todatetime (system. Data. datarowview) container. dataitem)

["Fbtime"]). tostring ("mm DD, YYYY") %>

<% # Databinder. eval (container, "dataitem. fbtime", "{0: Mm DD, yyyy}") %>

// String binding exceeds the specified length

<% # Databinder. eval (container. dataitem, "text"). tostring (). Trim (). length> 7?

Databinder. eval (container. dataitem, "text"). tostring (). Trim (). substring

(0, 7) atabinder. eval (container. dataitem, "text"). tostring (). Trim () %>

// The price lattice is converted into two decimal places

<% # Convert. todecimal (system. Data. datarowview) container. dataitem) ["price"]). tostring ("F2") %>

<% # Databinder. eval (container, "dataitem. Price", "{0: F2}") %>

'Vb. Net Price formatting before judgment
<% # IIF (databinder. eval (container. dataitem, "price", "{0: F2}") = "0.00", "negotiable", databinder. eval (container. dataitem, "price", "{0: F2}") + "Ten Thousand") %>

'Vb. Net General
<% # Ctype (container. dataitem, datarowview). Row ("title") %>

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.