Here is one way. Use two Panels as a container for two different CheckBoxLists. The first shows your "OT" -Items, and the last - "TO" -Items.
The second panel is initially invisible. In addition to CheckBoxList, it contains LinkButton to trigger the undo.
On BtnSelect that you add the selected items from the first to the second CheckBoxList and show it Panel. On BtnChangeSelection , you only need to switch the visibility of both panels and select the first element.
This already works with multiple selections.
ASPX (CSS is up to you):
<div> <asp:Panel ID="PnlChkListAcademicYear" runat="server"> <asp:CheckBoxList ID="ChkListAcademicYear" runat="server" /><br /> <asp:LinkButton ID="BtnSelect" Text="Select" runat= "server" ></asp:LinkButton> </asp:Panel> <asp:panel ID="PnlChkListAcademicYearActive" Visible="false" runat="server"> <asp:CheckBoxList ID="ChkListAcademicYearActive" Enabled="false" runat="server" /><br /> <asp:LinkButton ID="BtnChangeSelection" Text="Change selection" runat= "server" ></asp:LinkButton> </asp:panel> </div>
Codebehind:
Private Sub BtnSelect_Click(sender As Object, e As System.EventArgs) Handles BtnSelect.Click If Me.ChkListAcademicYear.SelectedIndex <> -1 Then Dim selectedItems = (From item In Me.ChkListAcademicYear.Items.Cast(Of ListItem)() Where item.Selected).ToArray Me.ChkListAcademicYearActive.Items.Clear() Me.ChkListAcademicYearActive.Items.AddRange(selectedItems) Me.PnlChkListAcademicYearActive.Visible = True Me.PnlChkListAcademicYear.Visible = False End If End Sub Private Sub BtnChangeSelection_Click(sender As Object, e As System.EventArgs) Handles BtnChangeSelection.Click Me.ChkListAcademicYear.SelectedIndex = 0 Me.PnlChkListAcademicYearActive.Visible = False Me.PnlChkListAcademicYear.Visible = True End Sub
This is the rest of my sample code for completeness:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindCheckboxList() End If End Sub Private Sub BindCheckboxList() Me.ChkListAcademicYear.DataSource = GetData() Me.ChkListAcademicYear.DataTextField = "Year" Me.ChkListAcademicYear.DataBind() End Sub Private Function GetData() As DataTable Dim years = {"2010/2009", "2009/2008", "2008/2007", "2007/2006", "2006/2005", "2005/2004", "2004/2003"} Dim tbl = New DataTable tbl.Columns.Add(New DataColumn("Year")) For Each y In years tbl.Rows.Add(y) Next Return tbl End Function
source share