ASP.NET 2.0 - 控件系列(四) – GridView绑定
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="StudentNumber">
<ItemTemplate>
<asp:CheckBox ID="snc" runat="server" Text='<% #DataBinder.Eval(Container.DataItem,"snumber") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sname" HeaderText="sname" SortExpression="sname" />
</Columns>
</asp:GridView>
The templatefield class is used to display custom content for each record displayed.
The DataBinder.Eval method is used to evaluate data-binding expressions at run time.