Gridview的绑定

大家做webform 通常会用到gridview ,下面我就总结一些gridview 的一些基本用法希望给大家可以带来帮助

1、griview 的绑定方式

<asp:TemplateField HeaderText="时间">

   <EditItemTemplate>

          <asp:Label ID="Label1" runat="server" Text='<%# Eval("sj", "{0:d}") %>'></asp:Label>

</EditItemTemplate>

<ItemTemplate>

          <asp:Label ID="Label2" runat="server" Text='<%# Bind("sj", "{0:d}") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 其中sj 是指 数据库中对应的字段名称,后面的是一些固定的格式

  后台绑定数据源 绑定list集合注意绑定之后要使用 databind

  List<Hetong> list = service_Hetong.GetPageList(searchModel, out rowCount);
GridView1.DataSource = list;
 GridView1.DataBind();

猜你喜欢

转载自www.cnblogs.com/w6w6/p/10971956.html