我创建了一个asp.net web表单页面,但是我来自MVC世界,由于我无法控制的原因,我已经使用了asp.net web表单,我对此非常无能为力。我发现很难调整。我正在尝试做的可能是不可能的 - 我正在尝试创建一个用户控件列表的用户控件。我可能使用这些东西都错了,但这就是我所拥有的:
单一控制项
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="testUserControl.ascx.cs" Inherits="testUserControl" %>
<tr>
<td><%= this.NewsId %></td>
<td><%= this.Title %></td>
<td><%= this.Body %></td>
<td><%= this.UserId %></td>
<td><%= this.DateCreated %></td>
<td><%= this.ImageId %></td>
</tr>
列出控制项
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="testListUserControl.ascx.cs" Inherits="testListUserControl" %>
<%@ Reference Control="~/testUserControl.ascx" %>
<table>
<% foreach (var userControl in TestUserControlItem)
{
userControl
} %>
</table>
列出控制项目代码
using System;
using System.Collections.Generic;
public partial class testListUserControl : System.Web.UI.UserControl
{
public List<testUserControl> TestUserControlItem { get; set; }
}
列表项是问题所在。它不起作用。你能看到我想做什么吗?有没有更好的方法来实现这一目标或让它发挥作用?