CodersBarn.com
The ASP.NET Community Blog

Bind CheckBoxList to DataSet

October 12, 2008 07:48 by agrace
Bind CheckBoxList to DataSet

 

Here's a code sample that might come in handy. This is a CheckBoxList for a fictitious Real Estate broker who wishes to maintain a list of features for each property listing entered in the system. Typically, you would create a form to add a listing and another to edit an existing listing. Loading the selected values for a CheckBoxList from the database often causes confusion and this snippet uses a Non-Typed-DataSet and a stored procedure.

CheckBoxList Data Table

 

CheckBoxList Markup

 

You may notice that there is also a custom validator used, to ensure that at least one selection has been made in the CheckBoxList. It would be nice to add a JavaScript version of this on the client also. The following snippet is part of the page load method.

CheckBoxList Validation

 

Here's the code to grab the selected values from the in-memory DataSet...

CheckBoxList Code

 

This is the call to the stored procedure from the DALC (Data Access Layer Class); the business layer method is simply a pass-through call.

CheckBoxList DALC

 

Next up is a pretty basic stored procedure which simply grabs the fields containing the text for the ChekBoxList items and the corresponding boolean value, indicating whether or not they were originally selected.

CheckBoxList Stored Procedure

kick it on DotNetKicks.com   PHP, ASP, .NET, JSP Resources, Reviews


Tags: ,
Categories: ASP.NET
Actions: E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

Comments

October 17. 2008 03:36

trackback

Trackback from DotNetKicks.com

Bind CheckBoxList to DataSet

DotNetKicks.com

February 13. 2009 12:08

trackback

Trackback from Kejames

【轉載】Bind CheckBoxList to DataSet

Kejames

June 21. 2009 01:44

trackback

Trackback from WebDevVote.com

Bind CheckBoxList to DataSet

WebDevVote.com

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading