日期:2014-05-17  浏览次数:20441 次

新手询问一个很简单的问题。
在gridview的模版列里面的控件。
  需要绑定数据源上的2个字段。 求教怎么做。。?



  详细说就是。 这列值需要显示时间, yyyy-mm-dd hh:MM:ss 
  但是数据库中一列为yyyy-mm-dd。 一列为hh:MM:ss  
  所以想在绑定时候这两列绑定到一个控件的text上去。
  像这个样子:

  <ItemTemplate>
  <clinput:LabelMap ID="LabelMap4" runat="server" MapDataField="" 
  Text='<%# Bind("sending_date")%> + <%# Bind("sending_time") %>>'>  
  </clinput:LabelMap>
  </ItemTemplate>

  希望在前台就能完成绑定。

------解决方案--------------------
那就在GridView1_RowDataBound事件中处理吧,可以将时间列隐藏,假如0是日期列,1是时间列,如下
C# code

      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          e.Row.Cells[0].Text = e.Row.Cells[0].Text + e.Row.Cells[1].Text;
      }

------解决方案--------------------
不懂!