zimcoder Level: VB Lord

 Registered: 27-10-2003 Posts: 225
|
Re: what is the use of DataBinder.Eval()
When you use a web control such as a datalist or datagrid you would normally set the datasource for this data display control to be a dataset or repeater.
// ds is your dataset and MyDataGrid is your datagrid
MyDataGrid.DataSource = ds;
MyDataGrid.DataBind(); |
These ADO.NET components will naturally have different fields that hold the data. You want to be able to resolve matching fields from your datasource to your control. The DataBinder class helps you to do this. It is from the System.Web.UI . the Eval method is an overloaded method of this class that allows you to evaluate and resolve an expression to an object at run time. You will be able to call the proper field from your datasource and bind it to the appropriate filed in your display control.
Here is an example
\\this piece of code resolves the datafield Price in the datasource to the label in the itemteplate of MyDataGrid
<asp:Label ID="mylabel"><%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %></asp:Label>
|
DataBinder.Eval() method will also do type cats/conversion implicitly for yu
____________________________
BrainBench ADO.NET and ASP.NET Certified Developer
 
|