如何在C#中设计HTML表 [英] How to design HTML table in C#

查看:59
本文介绍了如何在C#中设计HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

how to design html table in c# ???
how to pass sql server table values into html format in wpf apllication





我试过的:





What I have tried:

private void PDFSave()
        {
            string CmdString = string.Empty;
            using (SqlCeConnection conn = new SqlCeConnection(DBConnection.GetConnString()))
            {
                //CmdString = "select log.Username,log.EmailID,log.SchoolName,lt.LoginDate,lt.LogoutDate,lt.Medium from Login as log,LoginTime as Lt where log.EmailID = lt.EmailID   ";


                SqlCeCommand cmd = new SqlCeCommand("select log.Username,log.EmailID,log.SchoolName,lt.LoginDate,lt.LogoutDate,lt.Medium from Login as log,LoginTime as Lt where log.EmailID = lt.EmailID   ",conn);
                conn.Open();
              
                SqlCeDataAdapter read = cmd.ExecuteReader();
                cmd.ExecuteNonQuery();
                DataTable dt = new DataTable("Login");
                read.Fill(dt);
                string result = "<table class='table table-striped top-buffer'"
                + "style='width:300px'>"
                + "<tr><th>UserName(KG)</th><th>SchoolName</th><th>Date();</th></tr>";

                if (read.HasRows)
                {
                    while (read.Read())
                    {
                        Id = read["Id"].ToString();
                        System.Diagnostics.Debug.WriteLine(Id);

                        Weight = read["Weight"].ToString();
                        System.Diagnostics.Debug.WriteLine(Weight);

                        Rep = read["Rep"].ToString();
                        System.Diagnostics.Debug.WriteLine(Rep);

                        result += "<tr><td>" + Weight + "</td>"
                               + "</tr><tr><td>" + Rep + "</td></tr>";
                    }
                }
                else
                {
                    Console.WriteLine("nothing");
                }
                read.Close();

推荐答案

引用:

如何在c#中设计html表???

如何在wpf apllication中将sql server表值传递给html格式

how to design html table in c# ???
how to pass sql server table values into html format in wpf apllication





您不需要将数据导出为html格式!



您需要做的就是使用 DataGrid [ ^ ]控件,用于显示表格数据。



有关详细信息,请参阅:

包含行详细信息的DataGrid - 完整的WPF教程 [ ^ ]

WPF DataGrid实际示例 [ ^ ]

WPF Datagrid [ ^ ]



You don't need to export data into html format!

All you need to do is to use DataGrid[^] control, which is used to display tabular data.

For further details, please see:
DataGrid with row details - The complete WPF tutorial[^]
WPF DataGrid Practical Examples[^]
WPF Datagrid[^]


查看以下文章,解释如何使用带代码示例的C#创建动态html表,

CodeChef4U |使用C#创建动态HTML表 [ ^ ]
Check following post that explains how to create dynamic html table using C# with code sample,
CodeChef4U | Creating Dynamic HTML table using C#[^]


string WriteTable(DataTable dt)
{
    StringBuilder sb = new StringBuilder();

    sb.Append(@"
<table>
<tr>
<th>No</th>
<th>Code</th>
<th>Name</th>
</tr>
");

    foreach(DataRow dr in dt.Rows)
    {
        sb.Append("<tr>");
        sb.AppendFormat("<td>{0}</td>", dr["no"]);
        sb.AppendFormat("<td>{0}</td>", dr["code"]);
        sb.AppendFormat("<td>{0}</td>", dr["name"]);
        sb.Append("</tr>");
    }


    sb.Append("</table>");

    return sb.ToString();
}


这篇关于如何在C#中设计HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆