使用ASP.NET C#显示HTML表格中的所有数据 [英] Show all data in HTML table using ASP.NET C#
本文介绍了使用ASP.NET C#显示HTML表格中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨每个团体
i有一个页面,我需要在其中显示搜索数据我的数据库是excel假设我不知道有多少列和行我需要显示表中的所有数据依赖于列数如果excel表中有一列它在列上绘制了一个表,如果它们是列i excel sheet它在页面中绘制10列,那么表的标题应该在excel中相同
如何在asp.net中完成c#?
hi every body
i have a page that i need to show searched data in it my database is excel suppose i don't know how many columns and rows i need to show all data in a table depend on number of columns if there is one column in excel sheet it drew a table with on columns um if they are column i excel sheet it draw 10 columns in page and so on the header of the table should be the same in excel
how can it be done in asp.net c# ?
推荐答案
试试这个示例代码从Datatable创建一个HTML表,按照修改它你的需要。
Try this sample code to create an HTML table from Datatable, modify it as per your need.
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Rows.Add(1, "karthik", "bangalore");
dt.Rows.Add(2, "sehwag", "delhi");
dt.Rows.Add(3, "kavya", "coimbatore");
string html = "<table><thead ><tr>";
foreach (DataColumn column in dt.Columns)
html += "<td>" + column.ColumnName + "</td>";
html += "</tr></thead><tbody>";
foreach (DataRow row in dt.Rows)
{
html += "<tr>";
foreach (DataColumn col in dt.Columns)
html += "<td>" + row[col] + "</td>";
html += "</tr>";
}
html += "</tbody></table>";
lbl.Text = html;
这篇关于使用ASP.NET C#显示HTML表格中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文