Checking Bind Value in ASPX

  • Thread starter Thread starter Emre Guldogan
  • Start date Start date
E

Emre Guldogan

Hello,

In C#, We can read data fields from DB with <%#
DataBinder.Eval(Container.DateItem,"field_name") %>
but,
How can I check a value from DB with a <%# .. %> segment such as

<%# If( <condition> , <true_part> , <false_part>) %> ?

thanks...
 
Emre:
Take a look at http://openmymind.net/databinding/index.html#4 it talks
about how to format when databinding. Two options are to use inline (basic)
and the ItemDataBound event (good for more advanced control)

For example of inline, you could just do:

<%# SomeFunction(DataBinder.Eval(Container.DataItem, "Something")) %>

where SomeFunction is a function you can declare is codebehind and works
like any other function (in this case it expect 1 parameter). Take a look
at the tutorial (atleast that specific part, all would probably be useful
though). Should answer your questions.

Karl
 
does this code decrease performance/ speed ?

Karl Seguin said:
Emre:
Take a look at http://openmymind.net/databinding/index.html#4 it talks
about how to format when databinding. Two options are to use inline (basic)
and the ItemDataBound event (good for more advanced control)

For example of inline, you could just do:

<%# SomeFunction(DataBinder.Eval(Container.DataItem, "Something")) %>

where SomeFunction is a function you can declare is codebehind and works
like any other function (in this case it expect 1 parameter). Take a look
at the tutorial (atleast that specific part, all would probably be useful
though). Should answer your questions.

Karl
 
Hoz:
If you want to do processing, you have no choice but to do it. Obviously
simply outputing it is better, like <%# Databinder.Eval(Container.DataItem,
"Something") %> but if you need to check the value and do stuff based on
the results, you really don't have a choice but to take the hit. There will
be a performance hit, but it's minor, and as i've said, you really don't
have any choice.

Karl
 
Back
Top