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