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") %>