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