Pages

Monday, 20 August 2012

Loading selected items in a dynamic checkbox list

Suppose you are using a checkbox list whose ListItems are loaded dynamically from a database.
And you save the list of selected items into the database and wish to load the selected items when the page is loaded next time.

In the Page_Load Event, populate the List Items from the backend.
To set the last saved selected items, make use of the Page_PreRender Event.
Loop through the list of selected items you got from backend and use the FindItemByValue method of checkbox list to set the selected boolean value to true.

Page_PreRender event is used to make last minute changes to your controls before they are rendered.

No comments:

Post a Comment