Summary of databinder. Eval usage in Asp.net

Source: Internet
Author: User

I haven't used vs2003 for a long time, and I'm used to eval ("SS"). I'm not familiar with databinder many times, and I forgot to repost it online.

Databinder. Eval Summary 1. Basic Format of databinder. Eval

This sentence is often used when binding data.Program: <% # Databinder. eval (container. dataitem, "XXXX") %> or <% # databinder. eval (container, "dataitem. XXXX") %>

Today I learned another method, and Microsoft also said that this method is more efficient than the above two methods.

<% # (Datarowview) container. dataitem) ["XXXX"] %>

Very useful, so that you can do a lot of things on the front-end page.

Remember to import the namespace system. Data on the front-end page. Otherwise, an error message is generated.

<% @ Import namespace = "system. Data" %>

This usage is actually the same as <% # (dictionaryentry) container. dataitem). Key %>.

TEXT = '<% # databinder. eval (container. dataitem, "field") %>'
This method is the fastest

TEXT = '<% # getprice () %>'
You can also bind a method, but the method is public

TEXT = '<% # "cardetails. aspx? Carid = "+ databinder. eval (container. dataitem," carid ") %>'
You can also connect multiple fields.

The key is the container, which is mysterious. Its namespace is system. componentmodel. I need to further understand it.

2. Determine and select databinder. Eval
<Asp: templatecolumn headertext = "gender">
<Itemtemplate>
<% # Dgformatsex (convert. tostring (databinder. eval (container. dataitem, "XB") %>
</Itemtemplate>
</ASP: templatecolumn>

Define the dgformatsex method in CS
Protected string dgformatsex (string XB)
{
If (XB = "1 ")
Return "male ";
Else
Return "female ";
}

Example of databinder. Eval usage

// Display two decimal places
// <% # Databinder. eval (container. dataitem, "unitprice", "$ {0: F2}") %>

// {0: g} indicates that true or false is displayed.
// <Itemtemplate>
// <Asp: image width = "12" Height = "12" border = "0" runat = "server"
// Alternatetext = '<% # databinder. eval (container. dataitem, "discontinued", "{0: g}") %>'
// Imageurl = '<% # databinder. eval (container. dataitem, "discontinued ","~ /Images/{0: g2.16.gif ") %> '/>
// </Itemtemplate>

// Conversion Type
(String) databinder. eval (container, "dataitem. p_ship_time_sbm8"). substring (4, 4)

{0: d} date only displays year, month, and day
{0: yyyy-mm-dd} displays year, month, and day by format
{0: c} currency Style

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.