<高人>如何动态生成不规则表格,求动态生成表格方案 难
问:如何动态生成这种形式的表格
统计
_________________________
行业__|行业分类____|数量_|
保安 |公安________|2____| 数据库中(行业分类)=公安有2条记录,这2条记录的行业字段=保安
|武警________|3____|
|警察________|2____|
______|合计________|7____|
变电 |变电________|2____|
|变电站______|3____|
______|合计________|5____|
.
.
其中:行业是数据库中的UsrType字段,行业分类为UsrSubType
参考:
string connstr=System.Configuration.ConfigurationSettings.AppSettings["sqllink"];
SqlConnection conn=new SqlConnection(connstr);
conn.Open();
string sql="select UsrType,UsrSubType from view_usract";
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataReader dr=cmd.ExecuteReader();
this.Response.Write("<table align='center' border='1'>");
this.Response.Write("<tr>");
this.Response.Write("<td align='left'>");
this.Response.Write("用户行业");
this.Response.Write("</td>");
this.Response.Write("<td align='left'>");
this.Response.Write("行业分类");
this.Response.Write("</td>");
this.Response.Write("<td align='left'>");
this.Response.Write("用户数量");
this.Response.Write("</td>");
this.Response.Write("</tr>");
while(dr.Read())
{
this.Response.Write("<tr>");
this.Response.Write("<td align='left'>");
this.Response.Write(dr["UsrType"].ToString());
this.Response.Write("</td>");
this.Response.Write("<td align='left'>");
this.Response.Write(dr1["UsrSubType"].ToString());
this.Response.Write("</td>");
this.Response.Write("<td align='left'>");
this.Response.Write(dr1["UsrSubType"].ToString());
this.Response.Write("</td>");
this.Response.Write("</tr>");
}
this.Response.Write("</table>");
conn.Close();
--blackhero--