http://blog.csdn.net/w87875251l/archive/2010/11/02/5983301.aspx我要完成第二个图的一个报表的项目,但是遇到问题了,我只做到第一个图那了,用的repeater三层嵌套,
  private void bind()
  {
  SqlConnection conn = db.CreateConnection();
  string sql = "SELECT Company from gongsia union SELECT Company from gongsib";
  DataTable dt = new DataTable();
  conn.Open();
  SqlCommand cmd = new SqlCommand(sql, conn);
  SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  dt.Load(dr);
  Repeater1.DataSource = dt;
  Repeater1.DataBind();
  conn.Close();
  }
 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  {
  Repeater rep2 = (Repeater)e.Item.FindControl("Repeater2");
  rep2.ItemDataBound += new RepeaterItemEventHandler(Repeater2_ItemDataBound);
  SqlConnection conn = db.CreateConnection();  DataRowView row = (DataRowView)e.Item.DataItem;
  string str = row["company"].ToString();
  string sql = "select count(computer_idn) as zongshu,company from (select a.*,b.company from computer a,(select b.computer_idn,a.Company,b.IpAddress from gongsia a,BoundAdapter b where left(a.IpAddress,12)=left(b.IpAddress,12) union select b.computer_idn,a.Company,b.IpAddress from gongsib a,BoundAdapter b where a.ipaddress=b.ipaddress ) b where a.computer_idn=b.computer_idn and b.Company='" + str + "') a group by Company order by company";
  string sql1 = "select count(computer_idn)as geshu,Company from(select a.Computer_idn,b.ComPany,a.Reason,a.Vulnerability_Idn from CVDetected a,(select a.*,b.company from computer a,(select b.computer_idn,a.Company,b.IpAddress from gongsia a,BoundAdapter b where left(a.IpAddress,12)=left(b.IpAddress,12) union select b.computer_idn,a.Company,b.IpAddress from gongsib a,BoundAdapter b where a.ipaddress=b.ipaddress) b where a.computer_idn=b.computer_idn and b.Company='" + str + "') b where a.computer_idn=b.computer_idn and a.Vulnerability_Idn=2671) a group by Company order by Company";
  SqlDataAdapter da = new SqlDataAdapter(sql, conn);
  DataSet ds = new DataSet();
  da.Fill(ds);
  rep2.DataSource = ds;
  rep2.DataBind();
  }
  }
  // <asp:Label ID="label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"company") %>' ></asp:Label>
    
  //倒数第二层绑定
  protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  {
  Repeater rep3 = (Repeater)e.Item.FindControl("Repeater3");
  DataRowView row = (DataRowView)e.Item.DataItem;
  string str =row["company"].ToString();  DataRowView row1 = (DataRowView)e.Item.DataItem;
  int a = Convert.ToInt32(row1["zongshu"]);
  SqlConnection conn = db.CreateConnection();
  string sql = "select count(computer_idn)as geshu,Company from(select a.Computer_idn,b.ComPany,a.Reason,a.Vulnerability_Idn from CVDetected a,(select a.*,b.company from computer a,(select b.computer_idn,a.Company,b.IpAddress from gongsia a,BoundAdapter b where left(a.IpAddress,12)=left(b.IpAddress,12) union select b.computer_idn,a.Company,b.IpAddress from gongsib a,BoundAdapter b where a.ipaddress=b.ipaddress) b where a.computer_idn=b.computer_idn and b.Company='"+str+"') b where a.computer_idn=b.computer_idn and a.Vulnerability_Idn=2671) a group by Company order by Company";
  conn.Open();
  SqlDataAdapter da = new SqlDataAdapter(sql,conn);
  DataSet ds = new DataSet();
  da.Fill(ds,"a");
      rep3.DataSource = ds.Tables["a"];
  rep3.DataBind();
  conn.Close();
    
  }
  }
第四列是用第三列除以第二列作为第四列的值,能不能实现?不能的话应该怎么办?

解决方案 »

  1.   

    根据第二张表,建一个数据库表T。已知的是代理总数和存在威胁,把已知的插入表T,这时计算第四列百分比很容易。调用存储过程,或者直接用代码实现。和报表对应的数据库表T完成了,报表自然就出来了
      

  2.   

    思路应该是这样的:
    1.用DataGrid显示数据
    2.数据先在数据库中作好统计,DataGrid只是负责显示
    3.在DataGrid的OnItemDataBound事件中设置表头显示(思路,先clear掉表头,然后添加一列,再将表头的HTML写到改列的text即可)
      

  3.   

    我也是做报表的,不过我都是做成视图或者用存储过程插入到临时表!然后select * from table的!哈哈
      

  4.   

    第二个图就是个表头问题吧,你用一个Repeater+做好格式的表格或GridView在RowDataBound中处理下表头就行了(你这个google baidu 网上很多) 
    或者你也可以找第三方控件,如:DevExpress,不过一般收费,D的不好找,只能自己破
      

  5.   

    看过博客 典型的交叉报表 可以拆成两棵树来看 行列 各是一个树 这是lz的题目
    http://blog.csdn.net/w87875251l/archive/2010/11/02/5983301.aspx
      

  6.   

    可以先用sql视图先把想要的结果大休实现一下然后再做
      

  7.   

    建议你的sql查询用存储过程写好了 在调用。 你这个写 谁看了都晕。 别说找问题了。
      

  8.   

    这个先将需要的数据做成个一个视图,然后利用repeater的模板列实现就是了
      

  9.   

    看了半天,愣是没搞懂楼主的意思如果是我做此类表格1、将数据从数据库内取出,赋予泛型集合,或者字符数组、int数组2、数据逻辑处理之后,赋予DataTable或者泛型集合3、将DataTable或者泛型集合显示到网页
      

  10.   

    可以使用绑定模板列
    或者
    在SQL语句进行计算定义一个别名然后绑定这个别名就行
    复杂的报表为什么不使用水晶报表或者Report Service呢然后嵌到web页面呢
      

  11.   

    绑定第一个repeater里返回一个DataTable 看下
    private DataTable bind()
      {
      SqlConnection conn = db.CreateConnection();
      string sql = "SELECT Company from gongsia union SELECT Company from gongsib";
      DataTable dt = new DataTable();
      conn.Open();
      SqlCommand cmd = new SqlCommand(sql, conn);
      SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
      dt.Load(dr);
      Repeater1.DataSource = dt;
      Repeater1.DataBind();
      return dt;
      
      conn.Close();
     
      }
      

  12.   

    构造一个跟结果一样的DataTable
    1、可以通过sql语句(或者存储过程)得到一个DataTable
    2、或者重新组建一个DataTable
      

  13.   

    你的数据库操作在aspx.CS文件里啊……?
      

  14.   

    专业程序员连这么超级简单的统计报表都做不出来吗?看看人家用VBA做的统计报表,再对比你这个!!http://club.excelhome.net/viewthread.php?tid=281621&highlight=%2B%C5%ED%CF%A3%C8%CA
      

  15.   

    sql 里面有 函数、过程将结果建立成 视图。然后 将显示的数据从视图读取-----------------------------
    不然的话 在嵌套的 控件的rowdatabound 或 itemdatabound 事件里
    获取对应行列的值 计算结果 再赋值 给对应行列
      

  16.   

    根据第二幅图抽象出一个模型(也就是类),将数据填入此类,再将它绑定到repeater。
      

  17.   

    使用 pivot grid  可容易完成 .
      

  18.   

    用一个repeater 不就可以了 吗?
      

  19.   

    做报表打印的话,可以用DataGrid来显示或者repeater。
      

  20.   

      你还没弄过难的报表,我们上次弄一个难的里面的样式也要,也是动态的样式,根据选择的值不同,调用不同的样式,你这样的报表最好不要用控件,最原始的方法用字符串去拼
    或者用xslt去生成
      

  21.   

    用 GridView  来显示,数据吧,比较容易。
       代码也简单。
      

  22.   

    你用一个repeater  绑定下面的数据 用headtemplate 做表头就可以了
      

  23.   

    sql方面的建议去sql板块问问,那的牛人什么样的sql难题都能解决