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

Cast in ItemDataBound on RadGrid

1 Answer 92 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 21 Nov 2013, 08:15 AM

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?

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 25 Nov 2013, 11:41 AM
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.
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Shane
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or