2010-01-14 43 views
0

我有一个复选框列表,我绑定到一个主数据表(DTA)...我有另一个数据表(DTB)具有需要检查的值check-box-List ...因此,我循环查看复选框列表中的所有项目,以查看它是否存在于DTB中,并为存在的项目设置checked = true。基于选中的属性排序复选框列表

现在我想先在复选框列表框和未选中的项目下显示选中的项目。

有什么办法可以做到这一点...类似的List-Box解决方案也可能有所帮助。 Javascript提示也是受欢迎的。

感谢 - 拉贾

回答

1

如果要排序在服务器端的复选框列表,您可以首先从DTB添加项目的复选框列表和他们所选择的值设置为true ,然后添加其他形式的DTA和DTA中的每个项目,确保它不在项目列表中。
插入两个列表时,确保在需要时按照辅助排序标准对其进行排序。

如果您不需要在服务器端进行排序,那么您可以使用jQuery来轻松完成此操作。
你需要从服务器得到check_box_list_client_id,你可以使用
$('#<%= CheckBoxList1.ClientID %>') jquery选择器。


    $(function() { 
     // get the containing element - should be an HTML table 
     var cbl = $('#check_box_list_client_id'); 
     // check if the jquery element has any items in it 
     if (cbl.length) { 
      // get all the table rows, and filter out all those which 
      // doesn't contain a checked checkbox 
      var cbElements = cbl.find('TR').filter(function(index, element) { 
       return $(this).find('input:checked').length; 
      }); 
      // take each table row containing a checked checkbox and place it 
      // at the top of your check-box-list element we called cbl 
      cbElements.each(function() { 
       $(this).prependTo(cbl); 
      }); 
     } 
    }); 

完蛋了,希望它能给你,你需要的。