有点难度的问题,帮帮忙

w87875251l 2010-11-02 10:58:12
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控件,但是认为行不通啊
...全文
202 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
w87875251l 2010-11-04
  • 打赏
  • 举报
回复
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();
}
workhard_success 2010-11-03
  • 打赏
  • 举报
回复
如果列数不定的话,估计要考虑动态表格了。还有,表头和表数据,还有表尾,不一定是同一个<table/>,可以用三个,或者多个<table/>。
sunny_yu 2010-11-03
  • 打赏
  • 举报
回复
用一般的数据绑定控件都可以实现,数据在后台整合。整合绑定到前台就可以啦
w87875251l 2010-11-03
  • 打赏
  • 举报
回复
还是不行啊
w87875251l 2010-11-03
  • 打赏
  • 举报
回复
实现中,,,,
w87875251l 2010-11-03
  • 打赏
  • 举报
回复
哥哥们帮帮忙
w87875251l 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jxyxhz 的回复:]
dt.Columns.Add("zongshu", typeof(int));

foreach(datarow dr in dt.rows)
{
dr[zongshu]=你算出来的。
}
[/Quote]
看来没明白我的意思,“你算出来的”??这个你算出来的是个整型数值?
我的意思是那个链接表中有的整型字段是根据条件 用sql 中select count().....复杂的sql语句得到的,然后呈现到前台
w87875251l 2010-11-02
  • 打赏
  • 举报
回复
晕了。。。。
小_虎 2010-11-02
  • 打赏
  • 举报
回复
或者可以在后台添加一个方法

<asp:TemplateField>
<HeaderStyle ForeColor="White" HorizontalAlign="Center" />
<ItemTemplate>
<%# 你的方法() %>
</ItemTemplate>
</asp:TemplateField>
w87875251l 2010-11-02
  • 打赏
  • 举报
回复
jxyxhz 能不能具体点呢?你说使用repeater吗?可以实现吗?能不能给点具体代码吗?多谢了
小_虎 2010-11-02
  • 打赏
  • 举报
回复
dt.Columns.Add("zongshu", typeof(int));

foreach(datarow dr in dt.rows)
{
dr[zongshu]=你算出来的。
}
小_虎 2010-11-02
  • 打赏
  • 举报
回复
那你可以在后台动态给DataTable增加一个列
w87875251l 2010-11-02
  • 打赏
  • 举报
回复
是根据上面的dropdownlist的单位的值来进行查询
小_虎 2010-11-02
  • 打赏
  • 举报
回复
select c1,c2,(select count(*) from t2) as zongshu from t1


这样的逻辑可以不?

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧