Adam Schroder

Its Schotime.com!

Binding A String to a Checkbox

In a recent project I was attempting to list data from a configuration settings database table. The values were boolean but stored as a 'Y' or a 'N' so that only one set of SQL's was needed to be written, as the product supports both Oracle and SQL Server.

When I first put the GridView together, I was surprised to find that there was no Value property for the asp:checkbox nor could you bind any other column in a database but a 'bit' column to it.

The only solution I could come up with was to create a custom Checkbox and implement the feature.

Click here to keep reading and get the code...

Comments

Joe Chung said:

The ASP.NET CheckBox has a Checked property which you can set via data binding to true or false.  If you need to use the value attribute of the input[type="checkbox"] control, you can use a server-side input tag, i.e., <input type="checkbox" runat="server" />, if you want to data bind to that.

# April 2, 2008 2:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)