简体   繁体   中英

asp.net - dataTables - Uncaught TypeError: Cannot read property 'length' of undefined (zero config)

I have dataTables on my ASP.NET webforms app, in which the table will be generated by codebehind at Page_Load() before it shows up. This works on my other pages but for some reasons I don't understand, dataTables doesn't work on a page and it throws "datatables.min.js:42 Uncaught TypeError: Cannot read property 'length' of undefined". I'm using DataTables' Zero Configuration method.

Here's my code for Default.aspx:

<table id="jtable" class="table table-striped table-bordered UserTable"> 
                <thead>
                <tr>
                    <th>Job Title</th><th>Job Category</th><th>Date Posted</th><th>Actions</th>
                </tr>
                </thead>
                <tbody>
                <asp:Literal runat="server" ID="litJobPostings"></asp:Literal>
                </tbody>
            </table>

Code for the master file:

<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.prettyPhoto.js"></script>
<script src="js/jquery.isotope.min.js"></script>
<script src="js/main.js"></script>
<script src="js/wow.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/datatables.min.js"></script>

    <script>
        $(document).ready(function () {
            $('#jtable').DataTable();
        });
</script>

C# code for how the table will be generated:

while (reader.HasRows && reader.Read())
            {
                tablegen = tablegen + "<tr><td>" + reader.GetString(reader.GetOrdinal("JobTitle")) +
                            "</td><td>" + reader.GetString(reader.GetOrdinal("JobCategory")) + "</td><td>" + reader.GetString(reader.GetOrdinal("DatePosted")) +
                            "</td><td><a href = \"JobDetails.aspx?JobCode=" + reader.GetString(reader.GetOrdinal("PostID")) + "\">View/Edit Details</a></td><tr>";
            }
            reader.Close();
            litJobPostings.Text = tablegen;

So any ideas? Again, this works on my other pages but not on a single page I'm dealing and I'm so frustrated right now lol! Thanks! :)

Okay looks like I forgot to close the <tr> tag lol! I'm so confused that I forgot to close it lol!

tablegen = tablegen + "<tr><td>" + reader.GetString(reader.GetOrdinal("JobTitle")) +
                        "</td><td>" + reader.GetString(reader.GetOrdinal("JobCategory")) + "</td><td>" + reader.GetString(reader.GetOrdinal("DatePosted")) +
                        "</td><td><a href = \"JobDetails.aspx?JobCode=" + reader.GetString(reader.GetOrdinal("PostID")) + "\">View/Edit Details</a></td></tr>";

That should fix it :)

Thanks to Stanislav Šolc's comment for pointing it out! :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM