假设我有这个类:
public class Student {
private string _name;
private int _id;
public string Name
{
// get and set
}
public int ID
{
// get and set
}
}
我希望将它绑定到FormView上。
<asp:FormView runat="server" ID="FormView1">
<ItemTemplate>
<asp:Label runat="server" id="lblName" Text="<% Eval('Name') %>" />
</ItemTemplate>
</asp:FormView>
然而,当我尝试去执行时
FormView1.DataSource = student;
我会得到一个错误,说我必须实现iListSource、iEnumerable或IDataSource。
我不知道是否适用于IListSource和IEnumerable,并且我找不到一个好的示例来实现IDataSource。
这是针对asp.net的。