[英]Usercontrol with List<myclass> doesn't recognize public properties in myclass
I am attempting to do this: Post I Have Tried Over and Over But Failed 我正在尝试执行此操作: 我反复尝试但失败的帖子
But even after following the examples and the accepted answer I can't get my page to recognise the properties of the class in the List<>. 但是,即使按照示例和可接受的答案进行操作,我也无法使我的页面识别List <>中类的属性。
This is the code behind my UserControl: 这是我的UserControl背后的代码:
namespace TEST.ctrl.forms
{
public class listItem
{
public string Name { get; set; }
}
public partial class ddl : System.Web.UI.UserControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<listItem> ddlItem { get; set; }
}
}
And this is the aspx page: 这是aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frm_Test.aspx.cs" Inherits="TEST.forms.products.frm_Test" %> <%@ Register Src="~/ctrl/forms/ddl.ascx" TagPrefix="d" TagName="ddl" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>TEST</title> </head> <body> <form id="form1" runat="server"> <div> <d:ddl ID="ddl1" runat="server"> <ddlItem Name="Bob"></ddlItem> <ddlItem Name="Dave"></ddlItem> <ddlItem Name="Frank"></ddlItem> </d:ddl> </div> </form> </body> </html>
The page understands d:ddl and offers ddlItem as a property but doesn't know what ' Name ' is. 该页面理解d:ddl并提供ddlItem作为属性,但不知道“ Name ”是什么。 Am I missing something?
我想念什么吗?
ddlItem
is a List
so itself doesn't have a Name
property. ddlItem
是一个List
因此它本身没有Name
属性。 Your markup should look something like this: 您的标记应如下所示:
<d:ddl ID="ddl1" runat="server">
<ddlItem>
<asp:listItem Name="Alice" />
<asp:listItem Name="Bob" />
</ddlItem>
</d:ddl>
I'm not 100% sure you need the asp:
prefix. 我不确定100%是否需要
asp:
前缀。 You may need to register the listItem
class with another <%@ Register...
drective. 您可能需要向另一个
<%@ Register...
drective注册listItem
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.