Cast in ItemDataBound on RadGrid

Thread is closed for posting
2 posts, 0 answers
  1. Shane
    Shane avatar
    1 posts
    Member since:
    Dec 2012

    Posted 21 Nov 2013 Link to this post

    Here's my code:

    If e.CommandName <> "Preview" Then Exit Sub
     
    grdItem = CType(e.Item, GridDataItem)
    strFile = grdItem.OwnerTableView.DataKeyValues(grdItem.ItemIndex)("preview_file").ToString

    This handles a hyperlink button in the RadGrid, and it works fine. But if you try to apply a filter to the grid, you get the error:

    Unable to cast object of type 'Telerik.Web.UI.GridFilteringItem' to type 'Telerik.Web.UI.GridDataItem'.

    How do I get around this?

  2. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 25 Nov 2013 Link to this post

    Hi Shane,

    You have to check whether the item is GridDataItem and only in this case to cast it. In order to get the filter item you could use GetItems method. Please check out the following code snippet.
    Dim filter As GridFilteringItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)


    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top