2

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<>.

This is the code behind my 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:

<%@ 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. Am I missing something?

Community
  • 1
  • 1
FoxTC
  • 51
  • 7

1 Answers1

0

ddlItem is a List so itself doesn't have a Name property. 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. You may need to register the listItem class with another <%@ Register... drective.

DavidG
  • 113,891
  • 12
  • 217
  • 223