This is a migrated thread and some comments may be shown as answers.

RadListView Shows default ItemTemplate in list even though Setting OnItemDataBound

1 Answer 99 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 02 Jul 2012, 03:05 AM
Hey,

I call a method OnItemDatabound that loads a Control for the ItemTemplate. This works fine, however always at the top of the list the default ItemTemplate from the Markup shows?
Why is my default ItemTemplate showing in my list??
I always see the default "THIS IS THE DEFAULT TEMPLATE" at the top of my list and then the real list items display below that.
If I remove the <ItemTemplate> Then I see the contents of the EmptyDataTemplate only, and If I remove that my list becomes empty all together?

<telerik:RadListView ID="rlvJobsListPage" runat="server" ItemPlaceholderID="phJobsList" DataSourceId="objJobList"
    OnItemDataBound="rlvJobsListPage_ItemDataBound" AllowCustomPaging="true" AllowPaging="true" PageSize="20" AllowSorting="True">
    <LayoutTemplate>
        <div id="searchList">
            <div id="phJobsList" runat="server">

            </div>
        </div>
    </LayoutTemplate>
    <EmptyDataTemplate>
        No records found
    </EmptyDataTemplate>
    <ItemTemplate>
        THIS IS THE DEFAULT TEMPLATE<br />
    </ItemTemplate>    
</telerik:RadListView>
protected void rlvJobsListPage_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
{
    // Set each bound item to status "Loaded"
    if (e.Item is RadListViewDataItem)
    {
 
        RadListViewDataItem thisDataItem = (RadListViewDataItem)e.Item;
        Job thisListing = (Job)thisDataItem.DataItem;
         
        //Determine which template to get from cache
        Templating listingTemplate = Templating.GetTemplateForListing(thisListing.ListingTemplate);
        rlvJobsListPage.ItemTemplate = Templating.Render_ITemplate(listingTemplate.TemplatePath, TemplateType.Summary, this);
        e.Item.DataBind();
    }
}

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 04 Jul 2012, 12:40 PM
Hello,

 The ItemDataBound event is too late to assign a template because the first item from the ListView is already created there with the default template. In order to work correctly the template should be assigned earlier in the page life-cycle - such as Init or OnLoad events.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Simon
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or