Re: Databinding and setting control value in code not working?
From: Mark Essex (messex_at_nospam.netalytics.com)
Date: 09/04/04
- Next message: Lorenz Kahl: "Problem with DataView.Add() : the new item isn't shown/focused in the ListBox"
- Previous message: Mark Essex: "Re: Dataset Merge Question..."
- In reply to: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Next in thread: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Reply: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 4 Sep 2004 09:17:22 -0400
Regarding your #2 option, for a NEW row, you don't have values set yet.
Also, for this particular scenario, we are not retrieving the schema, so I
don't think the Default Value is being enforced. Not really sure. When you
say you set the value in the DB to be whatever you are going to show, do you
mean you set the 'DefaultValue' in the database to '0' for example?
Mark
"Sijin Joseph" <sijinNOSPAMdotnet@hotmail.com> wrote in message
news:%2381XFtkkEHA.3432@TK2MSFTNGP14.phx.gbl...
> I have used two workarounds depending on the situation.
>
> 1. Manually commit the selection in the UI control, either by calling
> OnValidating method of the base class or by moving focus away from the
> control via code(eek!!)
>
> 2. I set the value in the DB to be whatever i am going to show in the
> UI, so in your case instead of setting the value to DBNull i would set
> it to false, which is the UI default.
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
>
>
>
> Mark Essex wrote:
> > Is there an event that must fire if you set the value of an control in
code?
> > For example, I have a combobox that is bound to a dataset. If I
> > check/uncheck the combobox, everything is fine during the save.
However,
> > when I create a new Row in the dataset, the default value for the
checkbox
> > is DBNull. I have the 'Format' event set up to check for this
situation,
> > and if it is DBNull, set the value = false. I know this is working,
because
> > when I change this to set the value = true, the checkbox defaults to
> > checked. HOwever, the underlying datacolumn value is still DB Null. If
I
> > don't explicitly do something to that control (check it for example),
then
> > when I save, I get an exception saying 'xx value can't be null', or
> > something along those lines. I have seen this same behavior with
Textboxes.
> > If I tab intot the textbox and back out, it would fine, otherwise, the
value
> > I set in Code didn't appear to 'notify' the dataset of the change.
> >
> > Just wondering if anybody else has seen this behavior and if so, how did
> > they get around it.
> >
> > Thanks,
> >
> > Mark
> >
> >
- Next message: Lorenz Kahl: "Problem with DataView.Add() : the new item isn't shown/focused in the ListBox"
- Previous message: Mark Essex: "Re: Dataset Merge Question..."
- In reply to: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Next in thread: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Reply: Sijin Joseph: "Re: Databinding and setting control value in code not working?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|