C# 在ASPX网页中显示对象数据列表
我试图在网页中显示对象数据的简单列表。我只是让标签显示在输出中,没有数据。请告诉我这个代码可能有什么错误 我得到以下输出 名称C# 在ASPX网页中显示对象数据列表,c#,asp.net,.net,C#,Asp.net,.net,我试图在网页中显示对象数据的简单列表。我只是让标签显示在输出中,没有数据。请告诉我这个代码可能有什么错误 我得到以下输出 名称 年龄 城市 名称 年龄 城市 名称 年龄 城市 所需输出为 唐娜的名字 40岁 纽约市 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControl
年龄
城市 名称
年龄
城市 名称
年龄
城市 所需输出为 唐娜的名字
40岁
纽约市
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Customer : System.Web.UI.Page
{
public class myCustomer {
public String Name {get;set;}
public int Age { get; set; }
public String City { get; set; }
public myCustomer()
{
}
public myCustomer(string _name, int _age, string _city)
{
Name = _name;
Age = _age;
City = _city;
}
}
List<myCustomer> customerList;
protected void Page_Load(object sender, EventArgs e)
{
customerList = new List<myCustomer>();
myCustomer co1 = new myCustomer { Name = "Donna", Age = 40, City = "New York" };
myCustomer co2 = new myCustomer("Raj", 10, "New York");
myCustomer co3 = new myCustomer("Art", 16, "New York");
customerList.Add(co1);
customerList.Add(co2);
customerList.Add(co3);
testDataGrid.DataSource = customerList;
testDataGrid.DataBind();
}
}
<%@ Page Language="C#" CodeFile="customer.aspx.cs" Inherits="Customer" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="testDataGrid" runat="server" >
<ItemTemplate>
<table>
<tr><td>Name</td><td><asp:TextBox ID="Customer Name" Text= '<%# Eval("Name") %>' visible="true"/> </td></tr>
<tr><td>Age</td><td><asp:TextBox ID="Age" Text= '<%# Eval("Age") %>'visible="true" /></td></tr>
<tr><td>City</td><td><asp:TextBox ID="City" Text='<%# Eval("City") %>' visible="true" /></td></tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
名称Raj10岁
纽约市
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Customer : System.Web.UI.Page
{
public class myCustomer {
public String Name {get;set;}
public int Age { get; set; }
public String City { get; set; }
public myCustomer()
{
}
public myCustomer(string _name, int _age, string _city)
{
Name = _name;
Age = _age;
City = _city;
}
}
List<myCustomer> customerList;
protected void Page_Load(object sender, EventArgs e)
{
customerList = new List<myCustomer>();
myCustomer co1 = new myCustomer { Name = "Donna", Age = 40, City = "New York" };
myCustomer co2 = new myCustomer("Raj", 10, "New York");
myCustomer co3 = new myCustomer("Art", 16, "New York");
customerList.Add(co1);
customerList.Add(co2);
customerList.Add(co3);
testDataGrid.DataSource = customerList;
testDataGrid.DataBind();
}
}
<%@ Page Language="C#" CodeFile="customer.aspx.cs" Inherits="Customer" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="testDataGrid" runat="server" >
<ItemTemplate>
<table>
<tr><td>Name</td><td><asp:TextBox ID="Customer Name" Text= '<%# Eval("Name") %>' visible="true"/> </td></tr>
<tr><td>Age</td><td><asp:TextBox ID="Age" Text= '<%# Eval("Age") %>'visible="true" /></td></tr>
<tr><td>City</td><td><asp:TextBox ID="City" Text='<%# Eval("City") %>' visible="true" /></td></tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
名称艺术16岁
纽约市
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Customer : System.Web.UI.Page
{
public class myCustomer {
public String Name {get;set;}
public int Age { get; set; }
public String City { get; set; }
public myCustomer()
{
}
public myCustomer(string _name, int _age, string _city)
{
Name = _name;
Age = _age;
City = _city;
}
}
List<myCustomer> customerList;
protected void Page_Load(object sender, EventArgs e)
{
customerList = new List<myCustomer>();
myCustomer co1 = new myCustomer { Name = "Donna", Age = 40, City = "New York" };
myCustomer co2 = new myCustomer("Raj", 10, "New York");
myCustomer co3 = new myCustomer("Art", 16, "New York");
customerList.Add(co1);
customerList.Add(co2);
customerList.Add(co3);
testDataGrid.DataSource = customerList;
testDataGrid.DataBind();
}
}
<%@ Page Language="C#" CodeFile="customer.aspx.cs" Inherits="Customer" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater id="testDataGrid" runat="server" >
<ItemTemplate>
<table>
<tr><td>Name</td><td><asp:TextBox ID="Customer Name" Text= '<%# Eval("Name") %>' visible="true"/> </td></tr>
<tr><td>Age</td><td><asp:TextBox ID="Age" Text= '<%# Eval("Age") %>'visible="true" /></td></tr>
<tr><td>City</td><td><asp:TextBox ID="City" Text='<%# Eval("City") %>' visible="true" /></td></tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
公共部分类客户:System.Web.UI.Page
{
公共类myCustomer{
公共字符串名称{get;set;}
公共整数{get;set;}
公共字符串City{get;set;}
公共myCustomer()
{
}
公共myCustomer(字符串名称、整数年龄、字符串城市)
{
名称=_名称;
年龄=_年龄;
城市=_城市;
}
}
列出客户名单;
受保护的无效页面加载(对象发送方、事件参数e)
{
customerList=新列表();
myCustomer co1=新myCustomer{Name=“Donna”,年龄=40岁,城市=“纽约”};
myCustomer co2=新myCustomer(“Raj”,10,“纽约”);
myCustomer co3=新myCustomer(“第16条,纽约”);
customerList.Add(co1);
客户列表。添加(co2);
customerList.Add(co3);
testDataGrid.DataSource=customerList;
testDataGrid.DataBind();
}
}
名称
年龄
城市
您的文本框需要一个runat=“server”