如何使用数据表将数据显示到 <table> 标签中?

How to display data into <table> tag using datatable?

你好,我正在 VS Express for web 中做 web 项目,我对 c# 编程很陌生,只是调整它的语法和格式。我只是在徘徊如何在数据table中显示数据并在触发Button1_Click时将其显示在table网页中:

当我单击此按钮时,它将获取数据:

<button type="button" runat="server" onserverclick="Button1_Click" id="searchinfo" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Search Info</button>

并将其显示在我制作的 table 中: 我正在使用代码隐藏 (aspx.cs) 来控制我的网页,这是我到目前为止所做的:

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

namespace WebApplication1.eyeofheaven
{
    public partial class SearchCustomer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            DataSet selectedAngels = connector.ExecuteQuery("select * from customer where idcustomer = 453433");
            DataTable dt = selectedAngels.Tables[0];
        }

    }
}

使用data controls especially GridView.

在 .aspx 页面中添加以下标记

<asp:GridView runat="Server" id="data"/>

点击处理程序中的代码。

protected void Button1_Click(object sender, EventArgs e)
 {
   MSConnector connector = new MSConnector();
   connector.ConnectionString = "SERVER=xbetasql,52292;UID=username;Password=secret;DATABASE=ATDBSQL;";

   DataSet selectedAngels = connector.ExecuteQuery("select * from customer where idcustomer = 453433");
   DataTable dt = selectedAngels.Tables[0];
   data.DataSource = dt;
   data.DataBind();
   }