borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Leading Zeros)Next Topic (WebService and .net) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : what is the use of DataBinder.Eval()
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon what is the use of DataBinder.Eval()

please tell me what is the function of DataBinder and what is the function of Eval() method. what kind of job it does.
explain me in detail with example.

07-08-2004 at 07:33 AM
View Profile Send Email to User Show All Posts | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon 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

08-08-2004 at 06:26 PM
View Profile Send Email to User Show All Posts | Quote Reply
msbs48
Level: Trainee

Registered: 27-12-2004
Posts: 1
icon Re: what is the use of DataBinder.Eval()

A followup question on this.. I know is many moons later.
Qustion How does the .Eval(Container.Data)  make the connection to the dataset... there does not seem to be reference to the data set in the <%#DataBinder.Eval(Container.ItemData("Person")%> there could be multiple dataset binds.  So it is not clear how this statement makes the association on the Server to the correct dataset

Thanks

ben

27-12-2004 at 02:10 AM
View Profile Send Email to User Show All Posts | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: what is the use of DataBinder.Eval()

The association is made when the databind method is calles on the datagrid

____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

27-12-2004 at 07:22 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ASP.Net : what is the use of DataBinder.Eval()
Previous Topic (Leading Zeros)Next Topic (WebService and .net) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder