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.   

    大哥,写模版?怎么写?能不能给个例子或demo?
    帮帮忙,不然做不出来就只能滚蛋了
      

  2.   

    这个涉及到多行多列的表格最好是在后台写html代码绑定。
      

  3.   

    这个你就用HTML table来解决吧,你画出这个样子,然后填入数据就可以了。反正这个页面也就是呈现的
      

  4.   

    在后台写html的table,tr,td等,然后再绑定到前台。大概就这个意思。你没这样做过?
      

  5.   

    能不能给个例子或demo啊,大哥们,我一定得保住这个工作啊,我找了2个月才找到了个
      

  6.   

    用gridview,后台先画表头覆盖之前的,再填充数据,不是很麻烦
      

  7.   

    我个人有个办法
    一般做法
    1。先把需要的基础数据找出来
    2。针对datatable拆分计算得到多个你想要的数据源(datatable)
    3。分别绑定各个repeater控件
    其次我们针对上述的第2点做改进
    我们分别为我们需要的数据源建立视图,当然所谓列之间的计算就放在创建视图的过程中。总体来说我们有两种处理方法,不同的是一个是在程序的内存中计算,一个是在数据库服务器内存中计算。
      

  8.   

    用 Stringbuilder拼接好字符串 然后输出不会做??
      

  9.   

    你们就给他个demo撒,电信工作也不容易啊
      

  10.   

    不能用rdlc做报表么?
     又快,行列运算又简单
      

  11.   

    看了这么多楼侠,只有whb147(苦乐随缘)最有见解最有执行性。我们得学方法...先用excel做成一个模板,重新生成xml,然后操作xml、
      

  12.   

    第二个用gridview就可以做出啊,对表头进行下处理就好了
      

  13.   

    能不能具体点?或给个demo啥的?我菜鸟
      

  14.   

    Table Table1 = new Table();
     Table1.ID = "Table1";
     Table1.Attributes.Add("width", "100%");
     Table1.Attributes.Add("border", "1");
     Table1.Attributes.Add("cellpadding", "0");
     Table1.Attributes.Add("cellspacing", "0");
     Table1.Attributes.Add("bordercolorlight", "#CCCCCC");
     Table1.Attributes.Add("bordercolordark", "#FFFFFF");
    TableRow r = new TableRow();
     r.Height = 32;
    TableCell c = new TableCell();
     c.Text = "XXX";
     c.HorizontalAlign = HorizontalAlign.Center;
     c.ForeColor = System.Drawing.Color.Green;
     c.Font.Bold = true;
     c.BackColor = System.Drawing.Color.FromName("#E0FFE0");
     c.Attributes.Add("colspan", "2");
    r.Cells.Add(c); 
    Table1.Rows.Add(r);this.form1.Controls.Add(Table1)如果是我 我就用这种方式  当然GridView也能做
      

  15.   

    劝你像这样比较复杂的报表什么的。就不要用控件了。你可以试试用一下arraylist或者List<model>方法。
    如果用arraylist直接在前台套用html标签就可以了。想要显示数据直接用@XX。你可以上网查一上arraylist.方法。如果用List<model>方法的话。可以在aspx页使用foreach循环。至于显示百分比,或者别的。可以直接在前台去算!具体的去上网查一下。呵呵。看了一下你的代码。建议你使用三层开发。而不要把SQL语句直接写在页面的CS里。看着有些乱。
    GOOD LUCK TO YOU!