Expose ListView ItemTemplate inside UserControl and allow markup?
I'm trying to create a UserControl that contains a ListView and a number of other controls / methods we've been repeating for every list we create.
Is it possible to expose the ItemTemplate p开发者_StackOverflowroperty and allow markup for it when using the UserControl? I essentially want to add properties to the ListView but allow for the ease of design in an ASCX rather than programmatically creating all of my wrapping controls.
The markup for the UserControl so far;
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SuperListView.ascx.cs" Inherits="Sandbox.SuperListView" %>
<div class="listwrapper">
<h1>
<asp:Label ID="lbl_Header" runat="server" />
<asp:Button ID="cmd_CreateNew" runat="server" CssClass="create" />
</h1>
<asp:Panel ID="pnl_Filter" runat="server">
<h3><asp:Label ID="lbl_Filter" runat="server" /></h3>
<asp:Panel ID="pnl_FilterContents" runat="server">
</asp:Panel>
<asp:Button ID="cmd_Apply" runat="server" />
<asp:Button ID="cmd_Clear" runat="server" />
</asp:Panel>
<asp:ListView ID="frm_Data" runat="server">
<LayoutTemplate><div id="itemPlaceHolder" runat="server" /></LayoutTemplate>
</asp:ListView>
</div>
Faux-markup for what I hope to do with this UserControl;
<uc:SuperListView ID="frm_MyData" runat="server" Header="My Data">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</uc:SuperListView>
You will have to develop a custom server control to do this, which might not be practical if you have other controls in the user control.
It might be possible to expose the ItemTemplate, but user controls (ASCX) don't support child/nested elements, which is what you'd need to make it work.
精彩评论