How to bind data using databinder. eval ()

Source: Internet
Author: User

 


<% @ Import namespace = " System. Data "   %>
<% @ Import namespace = " System. Data. sqlclient "   %>
< Html >
< Script Language = " C # " Runat = " Server " >

Void Page_load (Object semder, eventargs E)
{
// Create a database connection string and sqldataadapter object
String Connstr = System. configuration. configurationsettings. deleettings [ " Connectionsqlserver_pubs " ];
Sqlconnection myconnection =   New Sqlconnection (connstr );
Sqldataadapter mycommand =   New Sqldataadapter ( " Select * from titles " , Myconnection );
// Generate DataSet object and fill in data
Dataset DS =   New Dataset ();
Mycommand. Fill (DS, " Titles " );
// Bind the Repeater control to data
Myrepeater. datasource = DS. Tables [ " Titles " ]. Defaultview;
Myrepeater. databind ();
}

</ Script >
< Body topmargin = " 0 " Leftmargin = " 0 " Marginwidth = " 0 " Marginheight = " 0 " >
< ASP: repeater ID = " Myrepeater " Runat = " Server " >
< Headertemplate >
< Table width = " 100% " Style = " Font: 8pt verdana " >
< Tr Style = " Background-color: dfa894 " >
< Th > Title </ Th >
< Th > Title ID </ Th >
< Th > Type </ Th >
< Th > Publisher ID </ Th >
< Th > Price </ Th >
</ Tr >
</ Headertemplate >
< Itemtemplate >
< Tr Style = " Background-color: ffecd8 " >
< TD >
<% # Databinder. eval (container. dataitem, " Title " ) %>
</ TD >
< TD >
<% # Databinder. eval (container. dataitem, " Title_id " ) %>
</ TD >
< TD >
<% # Databinder. eval (container. dataitem, " Type " ) %>
</ TD >
< TD >
<% # Databinder. eval (container. dataitem, " Pub_id " ) %>
</ TD >
< TD >
<% # Databinder. eval (container. dataitem, " Price " , " $ {0} " ) %>
</ TD >
</ Tr >
</ Itemtemplate >
< Footertemplate >
</ Table >
</ Footertemplate >
</ ASP: Repeater >
</ Body >
</ Html >

========================================================== ==================================

Databinder. Eval Method

Show all
Use reflection to analyze and compute the data binding expression of an object at runtime. This method allows the rad designer (such as Visual Studio. NET) to easily generate and analyze data binding syntaxes. This method can also be used on web forms pages through declaration to simplify conversions between types.

Reload list
Calculates the data binding expression during runtime.

[C #] public static object eval (object, string );

Calculate the data binding expression at runtime and format the result to the text to be displayed in the request browser.

[C #] public static string eval (object, String, string );

Example
[Visual Basic, C #, JScript] the following example shows how to use the eval method in Declaration to bind a price field. The container syntax used in this example assumes that you are using a list web server control. The format parameter format the number to set a specific currency string for the area displayed by the request browser.

[Visual Basic, C #, JScript] Note that this example shows how to use an overloaded version of eval. For other examples available, see separate overload topics.

[C #]
<% # Databinder. eval (container. dataitem, "price", "{0: c}") %>

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.