简体   繁体   English

jQuery表主体不与SQL数据一起显示

[英]Jquery Table Body Not Displaying with SQL Data

I am trying to pull data from my SQL database and display it in a Jquery DataTable. 我试图从我的SQL数据库中提取数据并将其显示在Jquery DataTable中。 I was able to do this with a Gridview but now want to change to a Jquery DataTable for more functionality. 我能够使用Gridview做到这一点,但现在想更改为Jquery DataTable以获取更多功能。 It seems like the data is being collected in my BindGrid() function but it will not actually display in the table on the webpage, the headers show but no information below them. 好像数据是在我的BindGrid()函数中收集的,但实际上不会显示在网页上的表中,标题显示,但下面没有信息。

Here is a picture of my web form right now: 这是我现在的网络表单的图片: 数据表中没有数据显示

Also, here is all of my code as it stands now: 另外,这是我目前的所有代码:

HTML: HTML:

<div style="margin-top:30px;">
        <table class="table table-striped table-bordered" style="font-family: serif; border:1px;" id="netEventTable" clientIdMode="static">
            <thead>
                <tr>
                    <th>ID</th> 
                    <th>Username</th>
                    <th>Type</th>
                    <th>Subject Line</th>
                    <th>Start Time</th>
                    <th>Estimated Time of Resolution</th>
                </tr>
            </thead>
            <tbody id="netEventTableBody" runat="server">

            </tbody>
        </table>
    </div>

JQUERY: JQUERY:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js" type="text/javascript"></script>
<link href="" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        $('#netEventTable').dataTable({
            "bLengthChange": true,
            "paging": true,
            "sPaginationType": "full_numbers",
            "jQueryUI": true,               
        });
    });
</script>

C# (CodeBehind): C#(代码隐藏):

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.BindGrid();
        }
    }

    private void BindGrid()
    {
        string strSQLConn = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
        try
        {
            // Jquery DataTable
            SqlConnection con = new SqlConnection(strSQLConn);
            con.Open();
            SqlCommand cmd = new SqlCommand("getNetEvents", con);
            SqlDataReader user = cmd.ExecuteReader();
            String UnreadText = "";
            Int32 i = 0;
            while (user.Read())
            {
                UnreadText += "<tr>";
                UnreadText += "<td class=\'center'>" + user["ID"] + "</td>";
                UnreadText += "<td class=\'center'>" + user["Name"] + "</td>";
                UnreadText += "<td class=\'center'>" + user["Type"] + "</td>";
                UnreadText += "<td class=\'center'>" + user["SubjectLine"] + "</td>";
                UnreadText += "<td class=\'center'>" + user["StartTime"] + "</td>";
                UnreadText += "<td class=\'center'>" + user["EndTime"] + "</td>";
                UnreadText += "</tr>";
                i++;
            }
            con.Close();


        }
        catch (Exception ex)
        {
            Console.WriteLine("ERROR: " + ex.ToString());
            Helpers.ApplicationLogHelper.createApplicationLogError("ERROR", ex.ToString());
            return;
        }
    }

How can I get the data from my SQL server to display in the Jquery DataTable? 如何从SQL服务器获取数据以显示在Jquery DataTable中?

I think you're missing this part, 我认为您缺少这部分,

"ajax": {
        url: 'some url',
        type: "GET",
        error: function (data) {
            //catch error
        }
    }

because you are just initializing the jquery datatable so it won't do anything at all. 因为您只是初始化jquery数据表,所以它根本不会做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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