前台代码:
<table width="100%">
<tr>
<td>
<%= table %>
</td>
</tr>
</table>
后台代码:
private string createTable(DataTable dt)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table width="100%">");
sb.Append("<tr class="head">");
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append(string.Format("<td style="100px">{0}</td>", dt.Columns[i].ColumnName));
}
sb.Append("</tr>");
for (int i = 0; i < dt.Rows.Count; i++)
{
sb.Append("<tr class="item">");
for (int j = 0; j < dt.Columns.Count; j++)
{
sb.Append(string.Format("<td style="100px">{0}</td>", dt.Rows[i][j]));
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
protected void btn_Select_Click(object sender, EventArgs e)
{
table = createTable(tj.FSFPCCJTJ_Select(ddlt_cjlx.SelectedValue, ddlt_fslx.SelectedValue, ddlt_pc.SelectedValue));
}