Eval method and ASP.Net expression

November 30th, 2006 · No Comments

Email This Post Email This Post

Normally we use to Eval method to print out value retrieved from database to HTML. For example:

asp:Label id=”lblDate” runat=”server” value=’<%# Eval(myDr["DateAdded"]) >’

Assuming “DateAdded” is a date/time field in database, the above statement returns a date/time value from database.

Now, if you would like to show only date portion of it. You should define format string within Eval, such as:

<%# Eval(myDr["DateAdded"], {0:d}) >

As mentioned in help file, the Eval function is used to define one-way (read-only) binding. There is another method called Bind, which is two-ways. We used <%# %> as data-binding expression. Another expression frequently used is <%$ %>, in which I normally use it to get keyword value from web.config, such as <%$ ConnectionStrings:myConnString %>.

No related posts.


Tags: Programming

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

CommentLuv badge

© 2006–2010 Now Eating — Sitemap

Switch to our mobile site