2016-05-25 30 views
1

我有一個asp:CheckBoxList到我的.aspx頁面。我希望將每個項目的asp:CheckBoxList分別作爲引導數據表的一行。我的代碼是像下面如何設置asp:CheckBoxList的每個項目到單獨的引導數據表的行ASP.NET

<asp:table id="tblUserToRoleList"> 
    <thead> 
     <tr> 
     <th> 
      Role List 
     </th> 
     <th></th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td> 
      <asp:CheckBoxList ID="chkRoleList" runat="server" Width="250px"></asp:CheckBoxList> 
     </td> 
     <td></td> 
     </tr> 
    </tbody> 

像這樣 enter image description here

輸出這裏所有的項目都下單TR

之一TD但我需要所有的項目單獨tr爲此,我可以從搜索項目bootstrap dataTable的默認搜索框

請幫我

回答

1

<asp:CheckBoxList>生成一個HTML table.The問題是,這個表沒有<th>元素定義和自舉的DataTable 需要這些標籤存在。

解決方法?手動添加<th>標籤之前調用DataTable();

<head runat="server"> 
    <title></title> 
    <link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" /> 

    <script src="//code.jquery.com/jquery-1.12.3.min.js"></script> 
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      debugger; 
      $("<thead><tr><th>Roles</th></tr><thead>").insertBefore("#chkRoleList tbody"); 
      $('#chkRoleList').DataTable(); 
     }); 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:CheckBoxList ID="chkRoleList" runat="server" Width="250px"></asp:CheckBoxList> 
    </form> 
</body> 

輸出: Bootstrap DataTable searching

+0

這正是我一直在尋找。 –

相關問題