DataTables warning: Requested unknown parameter `0` for row 0

。_饼干妹妹 提交于 2021-01-28 00:29:33

问题


I using vb.net. I use a dynamic datatable which can search, list, update and delete data. But my datatable works without any issue. But there is only one problem. When make the page which includes Datatables refresh, I get an popup error like this.

Error message popup here

<form  style =" margin-top : 220px;" id="form2" runat="server">
      <table  id="liste" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Sil</th>
                    <th>Düzenle</th>
                    <th>Proje Referans Numarası</th>
                    <th>Proje Adı</th>
                    <th>Proje Detay</th>
                    <th>Kullanacak Olan Departman</th>
                    <th>Başlangıç tarihi</th>
                    <th>Başlangıç Saati</th>
                    <th>Bitiş Tarihi</th>
                    <th>Bitiş Saati</th>
                </tr>
            </thead>

            <tfoot>
                <tr>
                    <th>Sil</th>
                    <th>Düzenle</th>
                    <th>Proje Referans Numarası</th>
                    <th>Proje Adı</th>
                    <th>Proje Detay</th>
                    <th>Kullanacak Olan Departman</th>
                    <th>Başlangıç tarihi</th>
                    <th>Başlangıç Saati</th>
                    <th>Bitiş Tarihi</th>
                    <th>Bitiş Saati</th>
                </tr>
            </tfoot>

            <tbody>
                <tr>
                    <%Dim strBaglanti As String = "Data Source=127.0.0.1;Initial Catalog=YOTK_TEST;Persist Security Info=True;User ID=username;Password=password"
                        Dim sayac = 0
                        Dim CN As New System.Data.SqlClient.SqlConnection(strBaglanti)
                        Dim strQ As String = "SELECT * FROM Proje"
                        Dim CMD As New System.Data.SqlClient.SqlCommand(strQ, CN)
                        CN.Open()
                        Dim Reader As System.Data.SqlClient.SqlDataReader = CMD.ExecuteReader()
                        Do While Reader.Read
                            Response.Write("<tr><td><center><a href='delete_project.aspx?id=" + Reader("ID").ToString() + "'><img width = '52px' height = '52px' src='css/images/delete.png'/></a></center></td><td><center><a href='edit_project.aspx?id=" + Reader("ID").ToString() + "'><img width = '52px' height = '52px' src='css/images/edit.png'/></a></center></td><td><center>" + Reader("ID").ToString + "</center></td><td><center>" + Reader("ProjeAdi").ToString + "</center></td><td><center><textarea style='width : 300px; height:100px;'>" + Reader("ProjeAciklama").ToString + "</textarea></center></td><td><center>" + Reader("Departman").ToString + "</center></td><td><center>" + Reader("BaslangicTarihi").ToString + "</center></td><td><center>" + Reader("BaslangicSaati").ToString + "</center></td><td><center>" + Reader("BitisTarihi").ToString + "</center></td><td><center>" + Reader("BitisSaati").ToString + "</center></td></tr>")
                        Loop
                        CN.Close()
                        %>
                </tr>
            </tbody>
    </table>
    </form>

This is my table code

<script src="http://cdn.datatables.net/plug-ins/1.10.7/integration/jqueryui/dataTables.jqueryui.js"></script>
<script>
    $(document).ready(function() {
        $('#liste').dataTable();
    } );
</script>

This is my JavaScript code. What is the problem?


回答1:


According to DataTables manual, one of the reasons it can occur is:

  • The number of cells in the table does not satisfy the equation #cells = #columns * #rows (i.e. there are more columns defined in the header than in the table body, or vice-versa).

You have extra <tr></tr> defined outside of your VB code. Below is a corrected code with other parts omitted for brevity.

            <tbody>
                    <%Dim strBaglanti As String = "Data Source=127.0.0.1;Initial Catalog=YOTK_TEST;Persist Security Info=True;User ID=username;Password=password"
                        Dim sayac = 0
                        Dim CN As New System.Data.SqlClient.SqlConnection(strBaglanti)
                        Dim strQ As String = "SELECT * FROM Proje"
                        Dim CMD As New System.Data.SqlClient.SqlCommand(strQ, CN)
                        CN.Open()
                        Dim Reader As System.Data.SqlClient.SqlDataReader = CMD.ExecuteReader()
                        Do While Reader.Read
                            Response.Write("<tr><td><center><a href='delete_project.aspx?id=" + Reader("ID").ToString() + "'><img width = '52px' height = '52px' src='css/images/delete.png'/></a></center></td><td><center><a href='edit_project.aspx?id=" + Reader("ID").ToString() + "'><img width = '52px' height = '52px' src='css/images/edit.png'/></a></center></td><td><center>" + Reader("ID").ToString + "</center></td><td><center>" + Reader("ProjeAdi").ToString + "</center></td><td><center><textarea style='width : 300px; height:100px;'>" + Reader("ProjeAciklama").ToString + "</textarea></center></td><td><center>" + Reader("Departman").ToString + "</center></td><td><center>" + Reader("BaslangicTarihi").ToString + "</center></td><td><center>" + Reader("BaslangicSaati").ToString + "</center></td><td><center>" + Reader("BitisTarihi").ToString + "</center></td><td><center>" + Reader("BitisSaati").ToString + "</center></td></tr>")
                        Loop
                        CN.Close()
                        %>
            </tbody>


来源:https://stackoverflow.com/questions/30843301/datatables-warning-requested-unknown-parameter-0-for-row-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!