看看这段代码,
自定义数据源类,
namespace dc
{
public class Student
{
public int Roll { get; set; }
public string Name { get; set; }
public Student() { }
public Student(int _roll, string _name)
{
Roll = _roll;
Name = _name;
}
}
public class StudentList : List<Student>
{
}
}
ASPX 标记,
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
dc.StudentList a = new dc.StudentList();
a.Add(new dc.Student(1, "A"));
a.Add(new dc.Student(2, "A"));
FormView1.DataSource = a;
FormView1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sample</title>
</head>
<body>
<form id="form1" runat="server">
<asp:FormView ID="FormView1" AllowPaging="true" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Roll") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>