Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将信息放在表aspx中_Html_Asp.net_Webforms - Fatal编程技术网

Html 将信息放在表aspx中

Html 将信息放在表aspx中,html,asp.net,webforms,Html,Asp.net,Webforms,我有这个ASPX代码: using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.OleDb; public partial class Default4 : System.Web.UI.Page {int i; public st

我有这个ASPX代码:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;


public partial class Default4 : System.Web.UI.Page
{int i;
    public string strAdmin;
    public string strPass;
    public string strLname;
    public string strEmail;
    public string strFname;
    public string str;

    protected void Page_Load(object sender, EventArgs e)
    {
        string dbPath = Server.MapPath(@"App_Data") + "/my_site.mdb";
        string connectionString = @"Data Source='" + dbPath + "';Provider='Microsoft.Jet.OLEDB.4.0';";
        OleDbConnection con = new OleDbConnection(connectionString);
        con.Open();
        string QueryString = "SELECT * FROM tbl_users";
        OleDbCommand cmd = new OleDbCommand(QueryString, con);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "tbl");
        con.Close();
        strt = 
        for (i = 0; i < ds.Tables[0].Rows.Count; i++)
        {

            strFname = ds.Tables[0].Rows[i]["first_name"].ToString();
            strLname = ds.Tables[0].Rows[i]["last_name"].ToString();
            strEmail = ds.Tables[0].Rows[i]["user_email"].ToString();
            strPass = ds.Tables[0].Rows[i]["user_password"].ToString();
            strAdmin = ds.Tables[0].Rows[i]["is_admin"].ToString();
            str += String.Format("{0}&nbsp{1}&nbsp{2}&nbsp{3}&nbsp{4}", strFname, strLname, strEmail, strPass, strAdmin);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用系统数据;
使用System.Data.OleDb;
公共部分类Default4:System.Web.UI.Page
{int i;
公共字符串strAdmin;
公共字符串strPass;
公共字符串strLname;
公共字符串邮件;
公共字符串strFname;
公共字符串str;
受保护的无效页面加载(对象发送方、事件参数e)
{
字符串dbPath=Server.MapPath(@“App_Data”)+“/my_site.mdb”;
字符串连接字符串=@“数据源=”+dbPath+”;提供程序='Microsoft.Jet.OLEDB.4.0';“;
OLEDB连接con=新的OLEDB连接(connectionString);
con.Open();
string QueryString=“选择*来自tbl\U用户”;
OleDbCommand cmd=新的OleDbCommand(查询字符串,con);
OleDbDataAdapter da=新的OleDbDataAdapter(cmd);
数据集ds=新数据集();
da.填写(ds,“待定”);
con.Close();
strt=
对于(i=0;i
如何在表格中显示此信息,使其更有用?
(我应该在这里添加哪些html标记?在哪里?)
我希望得到帮助

正如@David所提到的,对于这种类型的功能,您应该将数据绑定到DataGrid;但是,如果您确实希望将该数据集呈现到html表中(出于各种原因,如样式、强度javascript等),我将使用此函数返回数据集的html表示形式,然后使用返回的html填充div

    public static string BuildHTMLTable(DataSet dataSet)
    {
        var table = dataSet.Tables[0];
        var tableString = "<table>";

        tableString += "<thead>";

        for (var i = 0; i < table.Columns.Count; i++)
        {
            tableString += "<th>" + table.Columns[i].ColumnName + "</th>";
        }
        tableString += "</thead>";
        tableString += "<tbody>";

        for(var x = 0; x < table.Rows.Count; x++)
        {
            tableString += "<tr>";

            for (var y = 0; y < table.Columns.Count; y++)
            {
                tableString += "<td>";
                tableString += table.Rows[x][y];
                tableString += "</td>";
            }


            tableString += "</tr>";
        }

        tableString += "</tbody>";
        tableString += "</table>";

        return tableString;
    }
公共静态字符串BuildHTMLTable(数据集)
{
var table=dataSet.Tables[0];
var tableString=“”;
表字符串+=“”;
对于(var i=0;i
我假设您对ASP.NET非常陌生。我强烈建议您阅读下面的整篇文章,因为在我们回答您的问题之前,您需要很多基本的ASP.NET知识。如果你喜欢视频教程,我推荐第7课和第8课谢谢!你是对的,我是新来的,我不太了解,但这些是我明天的作业,范,你能帮我吗?看看第二个链接。特别是,您应该简单地使用GridView并将数据绑定到它。视频很短,很有说明性。非常感谢!没有比这更简单的方法来编写代码了?@NaveTseva不太简单,它只是通过循环内容来构建html表示。