C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to populate a CheckedListbox control using data from database


Posted Date: 16 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: shakti singh tanwarMember Level: Diamond    
Rating: Points: 10



The following code sample shows how to populate a CheckedListbox control using data from database

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio 8\Crystal Reports\Samples\en\Databases\xtreme.mdb");//Place your connection string here
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from orders";//Place your query here
cmd.Connection = con;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

foreach (DataRow dr in ds.Tables[0].Rows)
{
ListItem item = new ListItem(Convert.ToString( dr["Order Id"]) + "-" + Convert.ToString(dr["Customer Id"]));//Column names from table
item.Selected = (bool)dr["Shipped"]; //This is the boolean column in db based on which the checkbox will be either selected or deselected
CheckBoxList1.Items.Add(item);
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to get Image from database to ASP.Net page
Previous Resource: How to Remove all session values
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use