List of groups of grouped (nested) asp.net

I want to create a list of grouped checkboxes as follows:

[]Group1
  [] Item1
  [] Item2
[]Group2
  []Item1
  []Item2
  []Item3

The # groups and the # element are listed here. Does anyone know how to do this in asp.net. I get data from a DataSet. One limitation is that I am not allowed to use third-party tool / controls or jQuery.

Many thanks,

+3
source share
1 answer

Use a repeater (or nested repeaters) to create the layout and java-script for beaveavior. For example, let's say your dataset has two tables - "Groups" and "Elements" and the foreign key relationship between the tables "FK_Groups_Items". Then you can use a repeater like

<ol>
<asp:Repeater ID="Groups" runat="server">
<itemtemplate>
   <ul>
   <asp:CheckBox runat="server" ID="Group" Text="'<%# Eval("Name") %>'" Value='<%# Eval("Value") %>' onclick="OnGroupClick">
   <p class="nested">
     <asp:CheckBoxList runat="server" ID="Items" DataSource='<%# ((DataRowView)Container.DataItem).CreateChildView("FK_Groups_Items") %>'> DataValueField="Value" DataTextField="Name" />
   </p>
   </ul>
</itemtemplate>
</asp:Repeater>
</ol>

and after js function

function OnGroupClick(group) {
  for(item in group.getElementsByTagName('input')) {
     item.checked = group.checked;
  }
}

: , /

+5

All Articles