3

I want to create List of Grouped Checkboxes as follows:

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

Here Group# and item# are checkboxes. Does anyone know how to do this in asp.net. I am getting data from DataSet. One limitation is that I am not allowed to use third party tool/controls or jQuery.

Many thanks,

activebiz
  • 6,000
  • 9
  • 41
  • 64
  • If Group1 is checked also Item1 and Item2 should be checked? You should add more details on your requirement. It's not clear if you need a client-side functionality to check sub-items, if you need it on serveriside or if you only need the layout look grouped. – Tim Schmelter Mar 11 '11 at 08:24
  • Groups and items should be 'checkable' How they are checked I can manage this in javascript. My problem is how to populate this in 1st place. "if you need it on serveriside or if you only need the layout look grouped" - This is what I am looking for. – activebiz Mar 11 '11 at 08:51

1 Answers1

5

Use repeater (or nested repeaters) to generate layout and java-script for beahavior. For example, lets say your dataset has two tables - Groups and Items and there foreign key relation among tables named "FK_Groups_Items". Then you can repeater such as

<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 following js function

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

Disclaimer: untested code just to give an hint/idea of approach

VinayC
  • 47,395
  • 5
  • 59
  • 72
  • (DataRowView)Container.DataItem).CreateChildView("FK_Groups_Items") Does this related to the Foreign Key Constraint in the memory DataTables ? – activebiz Mar 11 '11 at 08:41
  • Let me make sure I understand the whole thing. (1) On repeater control I bind the in memoery joined Group and items table records. (2) then in the group checkbox it will get the group name then (3) in the 2nd checkbox it will use datasource to retrive child members using the FK constraints? Please let me know if I am missing something here? Thanks – activebiz Mar 11 '11 at 08:44
  • @activebiz, outer repeater will be bound to group tables so that it will create each row for group (don't bind with a join then you will get outer check-boxes for number of items) . Inner checklist has to be bound to items for that group (hence navigation by foreign key, if you have typed datasets then you will get a method such as GetItemsRow). – VinayC Mar 11 '11 at 13:01