Hey Guys,
I've come up against a sticky one here. I'm trying to apply a dynamic (from UserControl) ItemTemplate to my RadListView.
I do this OnItemDataBound and it works great except for the fact the ItemTemplate seems to have already been set up and so I end up modifying the template ready for the next record and not the current one. So all templates are staggered out-of-sync by one record.
It seems there is no event to handle that lets me check my dataitem in time to set the current ItemTemplate. I;ve read a solution online regarding the vanilla .NET ListView where you create a custom version which exposes what is effectively a "OnItemCreating" event where you can query the underlying data item in time to set the ItemTemplate accordingly.
I guess my question is really, have I missed something in Telerik's ListView that will allow me to do this? And if not, can I extend the Telerik ListView in the manner of that example and create an event where I can carry out my desired operations?
Many thanks for any help - code snippets below.
I've come up against a sticky one here. I'm trying to apply a dynamic (from UserControl) ItemTemplate to my RadListView.
I do this OnItemDataBound and it works great except for the fact the ItemTemplate seems to have already been set up and so I end up modifying the template ready for the next record and not the current one. So all templates are staggered out-of-sync by one record.
It seems there is no event to handle that lets me check my dataitem in time to set the current ItemTemplate. I;ve read a solution online regarding the vanilla .NET ListView where you create a custom version which exposes what is effectively a "OnItemCreating" event where you can query the underlying data item in time to set the ItemTemplate accordingly.
I guess my question is really, have I missed something in Telerik's ListView that will allow me to do this? And if not, can I extend the Telerik ListView in the manner of that example and create an event where I can carry out my desired operations?
Many thanks for any help - code snippets below.
<
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
>First item gets this default - not my dynamic template like the rest of them do</
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;
//Formulate the Template name and Render it!
rlvJobsListPage.ItemTemplate = Templating.Render_ITemplate(Globals.SectionIds.Jobs, thisListing.ListingTemplate, TemplateType.Summary,
this
);
}
}