问:如何动态生成这种形式的表格
统计
_________________________
行业__|行业分类____|数量_|  
保安  |公安________|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--

解决方案 »

  1.   

    用table控件可以實現,還可以把數據綁定到datagrid
      

  2.   

    好像是要合并单元格,这要用第三防控件才方便,可以试试 Syncfusion
      

  3.   

    建议你用datalist进行绑定,在该控件里面,你完全可以自由的画表格,达到你所要求的形式,然后绑定,就出来了.用服务端表格做,太麻烦.
      

  4.   

    我原来在一本书上看过一个例子,不知道对你有没有启发
    你不要用RESPONSE.WRITE("<table>")这一类的方法,在HTML控件中有一个表格控件,它有<table runat="server">其中又有rowcount和colcount什么属性(记不清楚了,你要去查些资料)然后你可以通过一个控件程序动态的生成各种各样的表格
      

  5.   

    datagird 里放datagrid
    谁有没有源代码呀(c#)
    我也给50分
    在线在线
    在线在线
    在线在线
    在线在线在线在线
    在线在线
    在线在线在线在线在线在线在线在线在线在线在线在线在线在线在线在线
      

  6.   

    你还是按原先的ASP模式写网页啊???? 用TABLE服务端控件啊
      

  7.   

    datagird 里放datagrid
    可以看http://dev.csdn.net/develop/article/65/article/67/67551.shtm