Note that there are some explanatory texts on larger screens.

plurals
  1. POUserControls nested tags
    primarykey
    data
    text
    <p>I want to encapsulate a ListView control into a simple User Control for easier reuse. Because the layout of the template is always the same (just line count and title headings differ) I thought I could generate it based on the following information: </p> <pre><code>&lt;asp:SimpleList ID="lstPersons" runat="server" DataSourceID="dsPersons" DataKey="PersonID" EnablePaging="true" Pager="Numeric"&gt; &lt;Columns&gt; &lt;Column Title="ID" DataField="PersonID" EnableSorting="true" SelectField="true" Width="30"/&gt; &lt;Column Title="First Name" DataField="FirstName" EnableSorting="true" Width="150"/&gt; &lt;Column Title="Last Name" DataField="LastName" EnableSorting="true" Width="150"/&gt; &lt;Column Title="Salary" DataField="Salary" EnableSorting="true" CssClass="numericValueCell" Width="50"/&gt; &lt;/Columns&gt; &lt;/asp:SimpleList&gt; </code></pre> <p>When you define public properties in the UserControl class they get available in the markup. But what if you have some kind of List as property. To assign this property in the markup you have to use nested tags within the UserControl definition (like in the example above). How can I do that? I thought that this would be an easy task, but I can't put the pieces together. </p> <p>This would be the code-behind code for the UserControl without any Attributes (just the properties so far).</p> <pre><code>namespace UserControls { public partial class SimpleList : System.Web.UI.UserControl { private ColumnCollection columns; public ColumnCollection Columns { get { if (this.columns == null) { this.columns = new MyListItemCollection(); } return this.columns; } } // Properties } public class ColumnCollection : List&lt;Column&gt; { } public class Column { // Properties } } </code></pre> <p>I was told that I just have to use the Attributes PersistenceModeAttribute and ParseChildrenAttribute, but how (I really tried)? I hope that dynamically generating the LayoutTemplate and ItemTemplate and binding it to a DataSource control is a little bit more straight forward. </p> <p>Thanks for your time. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload