0

This is my simple html code for bootstrap datatable

  <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>Rendering engine</th>
                                        <th>Browser</th>
                                        <th>Platform(s)</th>
                                        <th>Engine version</th>
                                        <th>CSS grade</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="odd gradeX">
                                        <td>Trident</td>
                                        <td>Internet Explorer 4.0</td>
                                        <td>Win 95+</td>
                                        <td class="center">4</td>
                                        <td class="center">X</td>
                                    </tr>
                                    <tr class="even gradeC">
                                        <td>Trident</td>
                                        <td>Internet Explorer 5.0</td>
                                        <td>Win 95+</td>
                                        <td class="center">5</td>
                                        <td class="center">C</td>
                                    </tr>
                                </tbody>


           </table>
 <script src="../bower_components/jquery/dist/jquery.min.js"></script>
    <script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../bower_components/metisMenu/dist/metisMenu.min.js"></script>
    <script src="../bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
    <script src="../bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
    <script src="../dist/js/sb-admin-2.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });
    </script>

It show like this enter image description here

But when I add this table into asp.net Repeater like

  <asp:Repeater runat="server" ID="repeater_Event">
                            <HeaderTemplate>
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Title</th>
                                            <th>Date</th>
                                        </tr>
                                    </thead>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tbody>
                                    <tr class="odd gradeX">
                                        <td><%# Eval("event_title") %></td>
                                        <td><%# Eval("event_date") %></td>
                                    </tr>
                                </tbody>

                            </ItemTemplate>
                            <FooterTemplate>
                                </table>


                            </FooterTemplate>
                        </asp:Repeater>
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../bower_components/metisMenu/dist/metisMenu.min.js"></script>
<script src="../bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="../bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<script src="../dist/js/sb-admin-2.js"></script>
<script>
$(document).ready(function() {
    $('#dataTables-example').DataTable({
            responsive: true
    });
});
</script>

the function such as Paging,Search and Sorting in datatable doesn't work .
How can I fix that ?

1 Answer 1

5

Your code returns more than one tag <body>...</tbody>:

<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
   <tr>
      <th>Title</th>
      <th>Date</th>
   </tr>
</thead>
   <tbody>
      .....
   </tbody>
   <tbody>
      .....
   </tbody>
   <tbody>
     .....
   </tbody>
</table>

Exclude tag <tbody> , </tbody> from <ItemTemplate> and add tag <tbody> in <HeaderTemplate>; in <FooterTemplate>, something like this:

<asp:Repeater runat="server" ID="repeater_Event">
     <HeaderTemplate>
        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
            <thead>
                <tr>
                    <th>Title</th>
                    <th>Date</th>
                </tr>
            </thead>
            <tbody>
      </HeaderTemplate>
      <ItemTemplate>

            <tr class="odd gradeX">
                <td><%# Eval("event_title") %></td>
                <td><%# Eval("event_date") %></td>
            </tr>

       </ItemTemplate>
       <FooterTemplate>
            </tbody>                                
            </table>
       </FooterTemplate>
</asp:Repeater>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.