Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to bind textbox, checkbox
Message
From
29/10/2009 19:56:42
 
 
To
29/10/2009 12:48:51
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MySQL
Application:
Web
Miscellaneous
Thread ID:
01432218
Message ID:
01432315
Views:
59
I don't see how your posted method would ever have anything to do with view, insert, update, delete, if you're talking about that in regards to your backend database. And it shouldn't anyway .. databinding to UI controls is totally separate from the DataAccess, which should be done in a different layer (or at least a different class) than the UI.

You are databinding to a DataSource that is either a DataTable, or a class that implements an interface for databinding (I think it's IBinding, but don't quote me on that ... I never have used it, since I do all my databinding to DataTables), or a BindingSource. You are NOT databinding directly to the database.

What you have shown should work, assuming a couple of things when the control parameter you pass is a CheckBox.

1) The dataMember that you are passing is of a boolean datatype.
2) The propertyName that it is binding to is "Checked".

Now, that said, you *can* databind a CheckBox to a string instead of a boolean, however you'd have to sub-class the CheckBox and add Format and Parse event handlers to the Binding object. If you need to databind to a string datatype rather than a boolean, let me know and I can post an example CheckBox sub-class.

~~Bonnie



>Hello The C# Expert,
>
>I am googling to find how to bind textbox, checkbox (view, insert,update,delete)..
>
>I found below routine..
>
>but some limitations;
>
>- unable to bind checkbox .. it return error (String was not recognized as a valid Boolean)
>
>- unable to do insert,update,delete.
>
>I need help
>
>TIA
>
>public void BindField(Control control, string propertyName, object dataSource, string dataMember)
> {
> Binding bd;
> for(int index = control.DataBindings.Count - 1; (index == 0); index--)
> {
> bd = control.DataBindings[index];
> if(bd.PropertyName == propertyName)
> control.DataBindings.Remove(bd);
> }
> control.DataBindings.Add(propertyName, dataSource, dataMember);
> }
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform