Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding Checkbox to nchar column
Message
De
31/01/2010 16:11:16
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01445996
Message ID:
01446768
Vues:
20
Yes, that is one bad thing about the .NET CheckBox ... it doesn't natively work with DBNull.Value. It's interesting that you have decided to set a default in a new row of 1 rather than 0. I would think that you'd want the CheckBox to default to un-checked rather than checked. But, hey, I don't know what your requirements are. Allowing NULLs in your database columns is not a bad thing, although I'm pretty sure that's one of those "religious" topics that'll get you differing opinions from everyone.

You're going to find lots of functionality in the native .NET controls that you don't like. Sub-classing them before-hand and using the sub-classes is definitely the way to go with .NET. When I started back in 2002, putting this DataBind() method in all my sub-classes was *critical* to the way I was using DataBinding. I suggest that you don't overlook this functionality in your own sub-classes.

~~Bonnie




>For once instead of asking you a question I will share with you something I found. I know now why when I was binding the check box using the syntax
>
>
>this.chkStatus.DataBindings.Add("Checked", bindingSource1, "VendorStatus");
>
>
>things would not work when moving in the grid to the new row. Or when creating a new row in code in my AddNew button. I am sure you already know that but the reason is that my column VendorStatus allows NULLs and when a new row is added in the grid the value set to the check box is NULL. And method DataBindings.Add has a problem with NULLs. I suppose this is why you created your own method DataBind(). So my solution will be NOT to allow user to add a new row while browsing the grid (I have not checked it but hopefully this property/setting exist). Then in my Add New button when adding a new row to the table I will set the value of the Check Box Column to 1. I just tested it and it works. Or better, I will change my database design not to allow NULLs and see if this setting will work too. But the good news is that I don't have to create a bunch of methods BindData in my subclasses. You see every time I create some code - since I am still learning a lot - I am bound (no pun intended) to make a mistake.
>
>I am sure I will be back with more questions as on every step of my development I am hitting a wall (my head hurts <g>).
>
>Thank you.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform