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

[Solved] NotSupportedException .Selectable

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matt
Top achievements
Rank 2
Matt asked on 10 Aug 2011, 09:54 AM

I have a bug in the following code whereby the MVC telerik grid control is throwing a NotSupportedException on the .Selectable() method. I have checked this by commenting and uncommenting the code and the error only occurs when .selectable() is in the code.

@(
Html.Telerik().Grid(Model).Name("Grid")
    .Columns(columns =>
        {
            columns.Bound(o => o.ManagerID);
            columns.Bound(o => o.Title);
            columns.Template(@<label>@item.User.Forename @item.User.Surname</label>);
            columns.Template(@<label>Email <a href="mailto:@item.User.Email">@item.User.Forename
                @item.User.Surname</a></label>).Title("Email this manager");
            columns.Template(@<label>@item.ManagerBranch.Count</label>).Title("Manager for no. Branches");
        }
    )
    .Scrollable(scrolling => scrolling.Enabled(true))
    .Sortable(sorting => sorting.Enabled((bool)true))
    .Pageable(paging => paging.Enabled((bool)true))
    .Filterable(filtering => filtering.Enabled((bool)true))
    .Groupable(grouping => grouping.Enabled((bool)true))
    .Footer((bool)true)
    .Selectable() @* Error being caused by this method, strange thing is this code is an exact copy of another view there the code is working correctly.*@
    .ClientEvents(click => click.OnRowSelected("onRowSelected"))
)

Full Error:

NotSupportedException was unhandled by the user code
The DataKeys collection is empty. Please specify a data key.
Message : The DataKeys collection is empty. Please specify a data key.
Source : Telerik.Web.Mvc
Stacktrace :           at Telerik.Web.Mvc.UI.Grid`1.VerifySettings()
   at Telerik.Web.Mvc.UI.ViewComponentBase.WriteHtml(HtmlTextWriter writer)
   at Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer)
   at Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString()
   at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString()
   at Telerik.Web.Mvc.{Dynamic}.GridBuilder`1\[\[TwistDataLayer.Manager\, TwistDataLayer\, Version=1.0.0.0\, Culture=neutral\, PublicKeyToken=null\]\].IHtmlString.ToHtmlString()
   at System.Web.HttpUtility.HtmlEncode(Object value)
   at System.Web.WebPages.WebPageBase.Write(Object value)
   at ASP._Page_Views_Manager_Index_cshtml.Execute() in c:\dev\Projects\twist\branches\development\AdminPortal\Views\Manager\Index.cshtml:line 10
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.StartPage.RunPage()
   at System.Web.WebPages.StartPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

1 Answer, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 27 Oct 2011, 04:12 PM
Hi Matt,

I found a reply here that says:
 

"As the exception says you need to define a datakey in order to enable grid selection:

.DataKeys(Sub (keys) keys.Add(Function(o) o.ManagerID) End Sub)"

Hope it helped.

Regards,

Tags
Grid
Asked by
Matt
Top achievements
Rank 2
Answers by
Anthony
Top achievements
Rank 1
Share this question
or