http://blog.csdn.net/w87875251l/archive/2010/11/02/5983301.aspx
如图,这样的报表如何实现?用什么报表?或用数据绑定控件可以吗?(如repeater),或用其他的??
注意:表中很多字段不是直接从数据库中读取的,而是根据数据库中表的字段用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
) a group by Company order by company我想着用reapter控件,但是认为行不通啊

解决方案 »

  1.   

    select c1,c2,(select count(*) from t2) as zongshu from t1
    这样的逻辑可以不?
      

  2.   

    是根据上面的dropdownlist的单位的值来进行查询
      

  3.   

    那你可以在后台动态给DataTable增加一个列
      

  4.   

    dt.Columns.Add("zongshu", typeof(int));foreach(datarow dr in dt.rows)
    {
       dr[zongshu]=你算出来的。
    }
      

  5.   

    jxyxhz 能不能具体点呢?你说使用repeater吗?可以实现吗?能不能给点具体代码吗?多谢了
      

  6.   

    或者可以在后台添加一个方法 <asp:TemplateField>
                                        <HeaderStyle ForeColor="White" HorizontalAlign="Center" />
                                        <ItemTemplate>
                                             <%# 你的方法() %>
                                        </ItemTemplate>
                                    </asp:TemplateField>
      

  7.   

    看来没明白我的意思,“你算出来的”??这个你算出来的是个整型数值?
    我的意思是那个链接表中有的整型字段是根据条件 用sql 中select count().....复杂的sql语句得到的,然后呈现到前台
      

  8.   

    如果列数不定的话,估计要考虑动态表格了。还有,表头和表数据,还有表尾,不一定是同一个<table/>,可以用三个,或者多个<table/>。
      

  9.   

    http://blog.csdn.net/w87875251l/archive/2010/11/02/5983301.aspx如图,第二列和第三列我做出来了,用了三层repeater嵌套,但是后面的第四类百分数是第二列除以第三列做为值,这个该怎么办?是不是三层太麻烦了?
      protected void Page_Load(object sender, EventArgs e)
        {
          
            if (!Page.IsPostBack)
            {
                binddrop();
                bind();
                //bind2();
            }
            
        }
      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);
                //Label la = (Label)e.Item.FindControl("label1");
                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();
             
            }
        }    //倒数第二层绑定
        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();         
                //Response.Write(a / b);
            } private void bind()
        {
            SqlConnection conn = db.CreateConnection();
            string sql = "SELECT Company from gongsia union  SELECT Company from gongsib";
            DataTable dt = new DataTable();
            //dt.Columns.Add("zongshu");
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            dt.Load(dr);
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
            conn.Close();
        }