Category classification as column in RadGrid
Hi,
I have created a RadGrid which loads items from the Sitefinity events module. In this module every item has a category. Now I want to display the name of the category (e.g. Mouse) in a column in the RadGrid.
This doesn't work, the following is displayed: "Telerik.OpenAccess.TrackedList`1[System.Guid]" instead of the name of the category.
How can I display the name of the category for an item in a new column?
Thanks!
Hi Steve,
Thank you for your time. I have tried something similar, but I was not able to bind it to a column. Do you perhaps have a working example where a category name of an item is binded to a column by it's uniqueName?
I think the easiest bet then is to make a proxy object with those taxa already resolved, then bind to that
Steve thank you, but I need a working example for this RadGrid with content from a dynamic module (created with the module builder). I have tried different approaches..still no luck!
So it would be appreciated if anyone has a working example of showing category name(s) in a RadGrid column, where a Sitefinity module / dynamic module is binded.
Does anyone has a working example of showing category name(s) in a RadGrid column?
I told you, you have the two choices...
1) Resolve them on ItemDataBound to each column
This is where you put the module builder code to get your items and bind them
www.telerik.com/.../grid-advanced-data-binding.html
...then in the GridTemplateColumn put in an asp:repeater. You can find the repeater in the ItemDataBound event then bind the resolved categories to it (get them using my extension)....or use a literal and loop and form the html yourself.
2) Resolve BEFOREHAND and bind to a custom object in NeedsDataSource...
Hi Steve,
I have used your extension and tried something out. I think i'm close but am getting an error: You are trying to access item that no longer exists.
The code is:
<
telerik:GridTemplateColumn
DataField
=
"Category"
HeaderText
=
"Country"
SortExpression
=
"Category"
UniqueName
=
"Category"
>
<
ItemTemplate
>
<
asp:Repeater
ID
=
"rptCountry"
runat
=
"server"
>
<
ItemTemplate
><%#DataBinder.Eval(Container.DataItem, "Category")%></
ItemTemplate
>
</
asp:Repeater
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
protected void rgEvents_ItemDataBound(object sender, GridItemEventArgs e)
if (e.Item is GridDataItem)
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
dynamicModuleManager.Provider.SuppressSecurityChecks = true;
Type SportType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Sports.Sport");
DynamicContent dynaItem = dynamicModuleManager.GetDataItem(SportType, e.Item.GetType().GUID);
Repeater countryRepeater = e.Item.FindControl("rptCountry") as Repeater;
if (countryRepeater != null)
countryRepeater.DataSource = GetCategories.GetCategory(dynaItem);
countryRepeater.DataBind();
Thank you for your support. I cannot find what's going wrong, i'm sure you will..
Hi guys,
You could try Steve's idea using a proxy object to assign the event properties which you want to display. Here is a sample which you can use on a simple aspx page to test:
Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BindGrid.aspx.cs" Inherits="SitefinityWebApp.BindGrid" %>
<%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
id
=
"sm"
runat
=
"server"
></
asp:ScriptManager
>
<
div
>
<
telerik:RadGrid
ID
=
"grid"
runat
=
"server"
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Sitefinity.Modules.Events;
using
Telerik.Sitefinity.Model;
using
Telerik.OpenAccess;
using
Telerik.Sitefinity.Taxonomies;
using
Telerik.Sitefinity.Taxonomies.Model;
namespace
SitefinityWebApp
public
partial
class
BindGrid : System.Web.UI.Page
protected
void
Page_Load(
object
sender, EventArgs e)
var manager = EventsManager.GetManager();
var events = manager.GetEvents().Where(ev => ev.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).ToList();
var dataSource =
new
List<ProxyItem>();
foreach
(var item
in
events)
var proxyItem =
new
ProxyItem();
proxyItem.title = item.Title;
var categories = item.GetValue<TrackedList<Guid>>(
"Category"
);
if
(categories.Count > 0)
TaxonomyManager tManager = TaxonomyManager.GetManager();
foreach
(var category
in
categories)
var catName = tManager.GetTaxon<HierarchicalTaxon>(category).Title;
proxyItem.category += catName +
"/"
;
proxyItem.category = proxyItem.category.Remove(proxyItem.category.LastIndexOf(
'/'
));
else
proxyItem.category =
"No category"
;
dataSource.Add(proxyItem);
grid.DataSource = dataSource;
grid.DataBind();
public
struct
ProxyItem
public
string
title
get
;
set
;
public
string
category
get
;
set
;
Hi Pavel,
Thank you for the provided code. I have used it and succesfully extended it to my needs.
Thank you both for the help!