1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
List<EmployeeAccounts> lst = GetEmployeeAccounts();
var sb = new System.Text.StringBuilder();
sb.Append(@"
<table class='table table-hover table-vcenter'>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Type</th>
<th>Email</th>
<th>Status</th>
</tr>
");
if(lst.Count==0)
{
sb.Append("<tr><td colspan='5'>No record</td></tr>");
}
else
{
foreach(var acc in lst)
{
sb.Append("<tr>");
sb.AppendFormat("<td>{0}</td>", acc.idNumber);
sb.AppendFormat("<td>{0}</td>", acc.fName);
sb.AppendFormat("<td>{0}</td>", acc.uType);
sb.AppendFormat("<td>{0}</td>", acc.email);
sb.AppendFormat("<td class='label label-table label-info'>{0}</td>", acc.status);
sb.Append("</tr>");
}
}
sb.Append("</table>");
string htmlTable = sb.ToString();
在 ASP.NET 頁面添加一個(gè)占位符:
<asp:PlaceHolder ID="ph1" runat="server"></asp:PlaceHolder>
然后在后面的代碼處,繼續(xù)編碼:
ph1.Controls.Add(new LiteralControl(htmlTable));
==================================
更新:版本 2(2019 年 10 月 25 日)
List<EmployeeAccounts> lst = GetEmployeeAccounts();
var sb = new System.Text.StringBuilder();
sb.Append(@"
<table class='table table-hover table-vcenter'>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Type</th>
<th>Email</th>
<th>Status</th>
</tr>
");
if (lst.Count == 0)
{
sb.Append("<tr><td colspan='5'>No record</td></tr>");
}
else
{
foreach (var acc in lst)
{
sb.Append($@"
<tr>
<td>{acc.idNumber}</td>
<td>{acc.fName}</td>
<td>{acc.uType}</td>
<td>{acc.email}</td>
<td class='label label-table label-info'>{acc.status}</td>
</tr>
");
}
}
sb.Append("</table>");
string htmlTable = sb.ToString();
- 1 回答
- 0 關(guān)注
- 160 瀏覽
添加回答
舉報(bào)