Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I am having a checkboxlist. On selection of few items, values is going to the database but in edit mode i want that all those items should be shown on page load which i have submitted in database. (The checkboxlist items should be shown selected.)


help me plz.
Thanks.
Posted
Comments
Mahesh Bailwal 6-Sep-13 6:35am    
where you got stuck?
ZurdoDev 6-Sep-13 7:40am    
What do you need help with?

1 solution

Assuming you have an Id and a Text property which you have binded to the checkbox list. Upon selection, the Id would get stored to the database.

So on page load, get the existing ids and iterate them and set the corresponding items in checkboxlist as checked.

C#
            CheckBoxList chkList = new CheckBoxList();  // This will be the checkboxlist
            List<int> ids = new List<int>();    // Populate this list from DB
            // Iterate over this list so as to select only these fields
            ids.ForEach(id =>
            {
                var item = chkList.Items.FindByValue(id.ToString());
                if (null != item)
                    item.Selected = true;
            });
</int></int>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900