Imagine you have a list of some items and checkboxes next to each item providing the ability for a user to make multiple choices and submit a result in one go. Weather you are implementing a news groups subscription, user survey or online products catalogue - the code behind is the same: we bind some object list to a data control like Repeater, add a checkbox to every item, set checkbox value to item ID.
Here is an example with list of books available for order
When “Order” button is clicked we need get all selected book IDs (we store them in a value field of each checkbox). I suggest that we create an extension method that will do all the work and when we need to get selected items in any repeater in our code we will have to call only one method GetSelectedItems
repeater 의 checkbox 선택한 값을 추출하는 확장 메소드를 구현하자
/// Returns selected items array list in a repeater rpt
/// <param name="chkBoxId">ID of a checkbox used in repeater to store the value of each item</param>
selectedValues array will contain BookIDs that were ordered and you can store them in the database or process as required by your code.
Note that this example assumes that you need to use <input runat=”server”… to be able to pre-polulate checked values or keep the state of the checkboxes after the postback. If none of this functionality is needed, the simplest way to get selected values is to use standard html