Re: How to handle null values in DataBinder.Eval()

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thank you for your answer!

"Chris Botha" wrote:

> Sorry, to elaborate, instead of having
> <%#
> Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))
> %>
>
> then you have
> <%#
> MyFunction(Container.DataItem,"tekst")
> %>
>
>
> "Chris Botha" <chris_s_botha@xxxxxxxxxxxxx> wrote in message
> news:OoO0haC2FHA.3124@xxxxxxxxxxxxxxxxxxxxxxx
> > Write a function in the code-behind and call the function (instead of
> > Server.HtmlDecode) with the column parameters, the function can check if
> > it is a null (int or string) and return what you want, else the function
> > calls Server.HtmlDecode.
> > Your idea of going through the table and change the nulls will work as
> > well.
> >
> > "eddy de boer" <eddydeboer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > news:62B2153D-FC7B-4F81-A830-A30275072FAB@xxxxxxxxxxxxxxxx
> >> Thank you for your answer.
> >>
> >> But how would I do that?
> >> Because if it is null, is it your intention to replace it with "" in case
> >> of
> >> a strng and a 0 in case of a integer?
> >>
> >> Then I should put the following code in the code behind like:
> >>
> >> ...
> >> for each (Column cl in ds.Tables[i].Rows[j].Columns) )
> >> {
> >> if (cl.IsDBnull(cl))
> >> {
> >> if (cl.Type == DataType.Integer)
> >> {
> >> cl.Value = 0;
> >> }
> >> ....
> >> }
> >> ds.ApplyUpdates()
> >>
> >> something like this?
> >>
> >> Or is there another way?
> >> "Scott M." wrote:
> >>
> >>> You should test for null using IsDBNull(object) prior to allowing the
> >>> value
> >>> in question to be used in your repeater.
> >>>
> >>>
> >>> "eddy de boer" <eddydeboer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >>> news:0F9749C0-80E4-4C2B-8350-FC0BDEC183D7@xxxxxxxxxxxxxxxx
> >>> > Hello,
> >>> >
> >>> > in my aspx page I have the followong code:
> >>> >
> >>> > <asp:Repeater id="Repeater1" runat="server">
> >>> > <ItemTemplate>
> >>> > ...
> >>> > <%#
> >>> > Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))
> >>> > %>
> >>> > ...
> >>> > </ItemTemplate>
> >>> > </asp:Repeater>
> >>> >
> >>> > Whereby "tekst" one of the columns is being loaded in the dataset
> >>> > In the code behind page data is loaded as as follows:
> >>> >
> >>> > ...
> >>> > meetmate.DataLayer.Meetings m = new meetmate.DataLayer.Meetings();
> >>> > ds = m.GetMeetingByID(meetingID);
> >>> > dr = ds.Tables[0].Rows[0];
> >>> > DataView dv = new DataView(ds.Tables[0]);
> >>> > this.Repeater1.DataSource = dv;
> >>> > this.Repeater1.DataBind();
> >>> > ...
> >>> >
> >>> > The problem is that column "tekst" can be null.
> >>> > In that case, I'm getting an error on
> >>> > <%#
> >>> > Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))
> >>> > %>
> >>> > because the (string) cast then goes wrong. If "tekst" is not null, it
> >>> > is
> >>> > ok.
> >>> >
> >>> > Now this is just for "tekst", but also other columns in my table could
> >>> > be
> >>> > null.
> >>> > How can I deal with this is a nice way?
> >>> >
> >>> > Eddy de Boer
> >>> >
> >>> >
> >>>
> >>>
> >>>
> >
> >
>
>
>
.