将Repeater Control与Datatable Jquery插件一起使用会产生不合需要的空间

时间:2017-07-11 03:16:14

标签: javascript c# jquery visual-studio datatables

我是代码新手 我使用转发器控件绑定来自ms sql server的数据以连接datatable jQuery插件。

我遇到了转发器创建的布局问题 如果我有一个大型数据库,则转发器将在表上方创建不必要的空间。

这是我的页面和代码。

在下图中,我拖动了由转发器控件创建的行空间,下面显示了数据表。

enter image description here

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class dFixtureRR : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!this.IsPostBack)
    {
      this.BindRepeater();
    }
  }

  private void BindRepeater()
  {
    string constr = ConfigurationManager.ConnectionStrings["AEdatabaseConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
      using (SqlCommand cmd = new SqlCommand("SELECT * FROM FixtureRR", con))
      {
        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
        {
          cmd.CommandType = CommandType.Text;
          DataTable dt = new DataTable();
          sda.Fill(dt);
          Repeater1.DataSource = dt;
          Repeater1.DataBind();
        }
      }
    }
  }
}


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dFixtureRR.aspx.cs" Inherits="dFixtureRR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <link href="Contend/css/jquery.dataTables.min.css" rel="stylesheet" />
    <link href="Contend/css/bootstrap.min.css" rel="stylesheet" />
    <script src="Contend/js/jquery-3.2.1.min.js"></script>
    <script src="Contend/js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="Contend/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        $('#example').DataTable();
      });
    </script>
    <title></title>
  </head>

  <body>
    <form id="form1" runat="server">
      <div class="container-fluid">
        <table id="example" class="display table-bordered" cellpadding="0" width="100%" >
          <thead>
            <tr>
              <th>
                No
              </th>
              <th>
                Drawing_Number
              </th>
              <th>
                Issue
              </th>
              <th>
                Short_Title
              </th>
              <th>
                Station
              </th>
              <th>
                Designer
              </th>
              <th>
                Drawing_Description
              </th>
              <th>
                Part_Number
              </th>
              <th>
                Status
              </th>
            </tr>
          </thead>
          <tbody>
            <asp:Repeater runat="server" ID="Repeater1" >
              <ItemTemplate>
                <tr>
                  <td>
                    <%#Eval("No")%>
                  </td>
                  <td>
                    <%#Eval("Drawing_Number") %>
                  </td>
                  <td>
                    <%#Eval("Issue") %>
                  </td>
                  <td>
                    <%#Eval("Short_Title") %>
                  </td>
                  <td>
                    <%#Eval("Station") %>
                  </td>
                  <td>
                    <%#Eval("Designer") %>
                  </td>
                  <td>
                    <%#Eval("Drawing_Description") %>
                  </td>
                  <td>
                    <%#Eval("Part_Number") %>
                  </td>
                  <td>
                    <%#Eval("Status") %>
                  </td>
                </tr>
              </ItemTemplate>
            </asp:Repeater>
          </tbody>
        </table>
      </div>
    </form>

  </body>
</html>

0 个答案:

没有答案