前台绑定我知道用<%# DataBinder.Eval(Container.DataItem,"字段") %>
但是有的字段是sql语句计算出来的,不是直接从数据库读取的,那该怎么办?
但是有的字段是sql语句计算出来的,不是直接从数据库读取的,那该怎么办?
解决方案 »
- 修改已发布的资料出现web.config配置错误
- asp.net 联动查询,请帮忙
- ASP.NET 生命周期?
- 将string字符串转换为实体类
- 这程序能坚持多久?
- VS2005 C#間體里做了一個小程序,在繁體中打開并運行有亂碼,怎解決?
- asp.net使用代理器不能访问应用程序?
- 我如何禁用datagrid的某行的按钮
- 各位做b/s的高手,我们公司要买套asp.net的b/s软件,请问网络是怎么设置的?需要一台带Microsoft .NET Framework v1.1的服务器,还用其他
- Microsoft .NET Connected Logo计划
- 检测文本
- html标签name冲突的问题有什么好的解决办法。
{
SqlConnection conn = db.CreateConnection();
//string sql = "select * from(SELECT Company from gongsia union SELECT Company from gongsib)a where Company='" + DropDownList1.SelectedValue + "'";
string sql = "select * from gongsia where Company='"+ DropDownList1.SelectedValue +"'";
SqlCommand cmd = new SqlCommand(sql,conn );
conn.Open();
Repeater1.DataSource = cmd.ExecuteReader();
Repeater1.DataBind();
conn.Close();
比如这个,但是前台我要绑定‘总数’,我写的总数的一个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 }
repeater前台绑定用<%# DataBinder.Eval(Container.DataItem,"字段") %>
字段就是数据库的字段,但是我还要绑定个字段,这个字段是根据数据库中的字段用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 }就是上面中的zongshu这个字段,该怎么办啊,急求
这个方法Eval(“字段”)中字段是填哪个?
可以使用给DataTable增加列的方法,合并为一个DataTable再绑定到Repeater或者在行的数据绑定事件中做处理,
{
SqlConnection conn = db.CreateConnection();
//string sql = "select * from(SELECT Company from gongsia union SELECT Company from gongsib)a where Company='" + DropDownList1.SelectedValue + "'";
string sql = "select * from gongsia where Company='"+ DropDownList1.SelectedValue +"'";
SqlCommand cmd = new SqlCommand(sql,conn );
conn.Open();
Repeater1.DataSource = cmd.ExecuteReader();
Repeater1.DataBind();
conn.Close();
}这个是绑定的第一列,是直接从数据库读取的
private int bi()
{
SqlConnection conn = db.CreateConnection();
conn.Open();
string sql = "select count(computer_idn) as zongshu 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";
SqlCommand cmd=new SqlCommand (sql,conn );
int a = cmd.ExecuteNonQuery();
conn.Close();
Response.Write(a);
return a;
}
然后我要绑定这个用sql语句算出来的a,绑定在地2列
然后后面的都是sql语句弄出来的,都绑定在repeater中
然后,把这些语句都写成一个视图最后会变为select 字段1,字段2,字段3 from 视图的形式,而这个视图所表示的就是你写的那个复杂的sql,这样绑定页面的时候不用顾忌,直接绑定视图的字段就Ok了
绑定直接 repeater.datasource = list;
前台绑定你的属性字段
dt.rows[i]["td_zdy"]="算出来的值";
前台绑定<%# DataBinder.Eval(Container.DataItem,"td_zdy") %>