我正在尝试这样做:Post I Have Tried Over and Over But Failed但是,即使按照示例和可接受的答案进行操作,我也无法使我的页面识别List 中类的属性。这是我的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; } }}这是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>该页面理解d:ddl并提供ddlItem作为属性,但不知道“名称”是什么。我想念什么吗? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 ddlItem是List,因此本身没有Name属性。您的标记应如下所示:<d:ddl ID="ddl1" runat="server"> <ddlItem> <asp:listItem Name="Alice" /> <asp:listItem Name="Bob" /> </ddlItem></d:ddl>我不确定100%是否需要asp:前缀。您可能需要向另一个listItem指令注册<%@ Register...类。 (adsbygoogle = window.adsbygoogle || []).push({});
10-08 03:48