Groups | Blog | Home
all groups > asp.net building controls > july 2004 >

asp.net building controls : Handling Nulls in Databinder.Eval



Jordan
7/20/2004 4:26:37 PM
I had a problem, now it's fixed, and now I have a concern on why isn't there
a better way. The question is: How do you handle NULLs in your control
based on the syntax: <%# DataBinder.Eval(Container.DataItem, "myfield") %>

Now coincidentally, this problem came up when I was calling a custom
function, and I handled this by adding the sytnax: ISNULL(myfield, '') to my
Stored Procedure. I also could have changed my custom function from
accepting a string parameter to an object parameter like:

private string myFunction (object myfeld) {
if (myfield.Equals(DBNull.Value) { ... }
}

Is there an inline way of detecting and remedying NULL values in the
DataBinder.Eval syntax without using custom functions?

j

Scott G.
7/22/2004 11:59:51 AM

This kind of depends on the context; if you are assigning a <%#... %> to =
a "string" like property then the parser will likely convert the DBNull =
to an empty string (you can see this if you create an error in an =
aspx/ascx file and look at the generated source, I think it uses a =
Convert method).

If you add your own function then you either have to test for DBNull or =
do something similar as the parser generated page; that is, convert the =
value to a string (and let the conversion generate an empty string by =
default).

Scott
[quoted text, click to view]
I had a problem, now it's fixed, and now I have a concern on why isn't =
there
a better way. The question is: How do you handle NULLs in your =
control
based on the syntax: <%# DataBinder.Eval(Container.DataItem, =
"myfield") %>

Now coincidentally, this problem came up when I was calling a custom
function, and I handled this by adding the sytnax: ISNULL(myfield, '') =
to my
Stored Procedure. I also could have changed my custom function from
accepting a string parameter to an object parameter like:

private string myFunction (object myfeld) {
if (myfield.Equals(DBNull.Value) { ... }
}

Is there an inline way of detecting and remedying NULL values in the
DataBinder.Eval syntax without using custom functions?

AddThis Social Bookmark Button