前台绑定我知道用<%# DataBinder.Eval(Container.DataItem,"字段") %>
但是有的字段是sql语句计算出来的,不是直接从数据库读取的,那该怎么办?

解决方案 »

  1.   

    一样的啊,你用sql语句算出来也是一个字段啊
      

  2.   

    <%#Get(Eval("字段")) %>写一个方法在后台计数!你可以描述你的问题更详细些! 
      

  3.   

     private void bind()
        {
            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    }
      

  4.   

    select (select count(*) from t1 where ...) + select count(*) from t2 where ....) from dual 看看对你有帮助吗?
      

  5.   

    谁会啊,哥们帮帮忙,我在解释一下
    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这个字段,该怎么办啊,急求
      

  6.   

    直接把SQL语句使用SqlDataAdapter Fill到一个DataTable里,再把DataTable绑定到Repeater,而这个DataTable里面的行数是不是就是总数?如果不是,再拿着这个DataTable再计算一下也行啊
      

  7.   

    这不就是个字段吗?直接绑定就行了,或者说你只需要绑定在footer栏目,而不需要每行都绑定。
      

  8.   

    有些字段是数据库统计出来的,你在repeat那里先放个label什么的 ,然后再后台用repeat的行绑定来找这个label,在后台获取数据库统计出来的值,赋值给这个label。
      

  9.   

    <%#Get(Eval("字段")) %>写一个方法在后台计数!你可以描述你的问题更详细些! 
    这个方法Eval(“字段”)中字段是填哪个?
      

  10.   

    直接在后台datatable里加个字段
      

  11.   

    是不是你有两次数据查询啊?
    可以使用给DataTable增加列的方法,合并为一个DataTable再绑定到Repeater或者在行的数据绑定事件中做处理,
      

  12.   

    <%# DataBinder.Eval(Container.DataItem,"zongshu") %>
      

  13.   

    有n多的数据查询呢http://topic.csdn.net/u/20101102/22/dbe4d25a-9300-4ef7-b518-3b778b7ed2d6.html
      

  14.   

       private void bind()
        {
            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中
      

  15.   

    如果你是在纠结于这个计算的话,可以这样,把任何复杂的计算方式最后用(计算的slq) as '字段' 写好
    然后,把这些语句都写成一个视图最后会变为select 字段1,字段2,字段3 from 视图的形式,而这个视图所表示的就是你写的那个复杂的sql,这样绑定页面的时候不用顾忌,直接绑定视图的字段就Ok了
      

  16.   

     直接写个实体类,把读出来的数据存在List<实体类> 中
    绑定直接 repeater.datasource = list;
    前台绑定你的属性字段
      

  17.   

    用dataset绑定吧 commandtext写两个 一个是以前  以后是后来计算的 然后再填充两个table
      

  18.   

    在sql语句中用别名,在绑定别名,如:"select a as  b from...."
      

  19.   

    直接Eval("字段")就可以了.这个字段和是不是从数据库读取出来的没有关系.是决定你绑的的数据源对象有没有这个数据项.
      

  20.   

     dt.Columns.Add("td_zdy", typeof(string));
    dt.rows[i]["td_zdy"]="算出来的值";
    前台绑定<%# DataBinder.Eval(Container.DataItem,"td_zdy") %>