/*
比如:在数据库中查询一个DataTable的数据是这样Name Url CreateTime 
百度 www.baidu.com 2012-5-29 15:49:27 
新浪 www.sina.com 2012-5-29 15:49:27 
谷歌 www.google.com 2012-5-29 15:49:27 我想在绑定之前将url这一列所有行追加http://,在不循环DataTable的情况下 可以实现吗想要的结果:
百度 http://www.baidu.com 2012-5-29 15:49:27 
新浪 http://www.sina.com 2012-5-29 15:49:27 
谷歌 http://www.google.com 2012-5-29 15:49:27 
*/

解决方案 »

  1.   

    第一可以通过sql
    select Name 'http://'+Url as NewUrl,CreateTime from xxx第二可以通过GridView1_RowDataBound事件,对这一列加上http,比如  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Cells[0].Text = "http://" + e.Row.Cells[0].Text;
          }
      }
      

  2.   

    第一可以通过sql
    select Name 'http://'+Url as NewUrl,CreateTime from xxx第二可以通过GridView1_RowDataBound事件,对这一列加上http,比如  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Cells[0].Text = "http://" + e.Row.Cells[0].Text;
          }
      }
      

  3.   

    var list=dt.AsEnumerable().Select(t=>new
    {
          Name=t.Field<string>("Name"), 
          Url=t.Field<string>("Url").StartWith("http")?t.Field<string>("Url"):"http://"+t.Field<string>("Url"),
           CreateTime =t.Field<DateTime>("CreateTime ")
    });
      

  4.   


    sql中可以排除 GridView1_RowDataBound 是查询出来数据 然后导出的
      

  5.   

    var list=dt.AsEnumerable().Select(t=>new
    {
      Name=t.Field<string>("Name"),  
      Url=t.Field<string>("Url").StartWith("http")?t.Field<string>("Url"):"http://"+t.Field<string>("Url"),
      CreateTime =t.Field<DateTime>("CreateTime ")
    });指定转换无效
      

  6.   

     CreateTime =t.Field<DateTime>("CreateTime ")
    这个字段是否为datatime格式,如果不是,改成string