views:

39

answers:

1

Hi

Take following example of code: (ASP.NET WebForms)

<asp:Content ContentPlaceHolderID="Contents" runat="server">
    <div class="blogpost-list">
        <asp:Repeater ID="blogList" runat="server">
            <ItemTemplate>
                <h2 class="blogpost-title">
                    <%# (Container.DataItem as BlogPost).Title %>
                </h2>
                <p class="blogpost-meta">
                </p>
                <p class="blogpost-content">
                    <%# (Container.DataItem as BlogPost).ParsedContent %>
                </p>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</asp:Content>

Now what I want to do, is to avoid the content casting of the DataItem, ie. this line:

<%# (Container.DataItem as BlogPost).Title %>

I'm feeling inspired of the ASP.NET MVC, and was wondering if I could create a strong typed, view, and define it like:

<%@ Page
    Language="C#" MasterPageFile="~/Blog.Master" 
    AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
    Inherits="MyBlog.Default<MyStrongViewType>"
%>

Or any other way to avoid typecasting, and in general, have a strong typed view for ASP.NET WebForms.

Any good ideas?

A: 

I think you can inherit from Repeater control and make it generic (e.g. Repeater). But you'll need to rewrite/inherit RepeaterItem class too.
You can use this or this article as example.

zihotki