I am working on a project that would benefit from adding a RadGrid to a CompositeControl. The grid works as expected until I attempt to handle the ItemCreated event which results in the following exception: Unable to cast object of type 'Telerik.Web.UI.GridItemEventHandler' to type 'Telerik.Web.UI.GridItemEventHandler'.
I have submitted a Telerik support ticket requesting assistance with this exception and to see if there is a different way of doing what I need. Unfortunatly after several exchanges with support I have found myself stuck in a "it works for me" loop.
Is there anyone in the community who can see an issue with the way I have coded this CompositeControl or is there a better/different way to create a CompositeControl containing a RadGrid that handles events that I can test?
Thank you!
CustomControls.dll (The CompositeControl with RadGrid)
Default.aspx
Default.aspx.cs
Exception
[InvalidCastException: Unable to cast object of type 'Telerik.Web.UI.GridItemEventHandler' to type 'Telerik.Web.UI.GridItemEventHandler'.]
Telerik.Web.UI.RadGrid.OnItemCreated(GridItemEventArgs e) +110
Telerik.Web.UI.RadGrid.CallOnItemCreated(GridItemEventArgs e) +39
Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +986
Telerik.Web.UI.GridTableView.CreateHeaderItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead) +126
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +980
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +802
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
Telerik.Web.UI.GridTableView.PerformSelect() +28
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
Telerik.Web.UI.GridTableView.DataBind() +368
Telerik.Web.UI.RadGrid.DataBind() +165
Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3855
Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +177
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.AddedControl(Control control, Int32 index) +265
System.Web.UI.ControlCollection.Add(Control child) +80
Company.CustomControls.CustomGrid.CreateChildControls() in C:\Data\CompositeControlGrid\TelerikTesting\CustomControls\CustomGrid.cs:28
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +84
I have submitted a Telerik support ticket requesting assistance with this exception and to see if there is a different way of doing what I need. Unfortunatly after several exchanges with support I have found myself stuck in a "it works for me" loop.
Is there anyone in the community who can see an issue with the way I have coded this CompositeControl or is there a better/different way to create a CompositeControl containing a RadGrid that handles events that I can test?
Thank you!
CustomControls.dll (The CompositeControl with RadGrid)
using System.ComponentModel; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using Telerik.Web.UI; | |
namespace Company.CustomControls | |
{ | |
[ToolboxData("<{0}:CustomGrid runat=server></{0}:CustomGrid>")] | |
public class CustomGrid : CompositeControl, INamingContainer | |
{ | |
private RadGrid _MainGridView; | |
public CustomGrid() { | |
_MainGridView = new RadGrid(); | |
} | |
public object DataSource { | |
get { return _MainGridView.DataSource; } | |
set { _MainGridView.DataSource = value; } | |
} | |
protected override void CreateChildControls() { | |
Controls.Add(new LiteralControl("Custom Grid:<br />")); | |
_MainGridView.AutoGenerateColumns = true; | |
Controls.Add(_MainGridView); | |
} | |
public event GridItemEventHandler ItemCreated { | |
add { _MainGridView.ItemCreated += value; } | |
remove { _MainGridView.ItemCreated -= value; } | |
} | |
} | |
} |
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> | |
<%@ Register assembly="CustomControls" namespace="Company.CustomControls" tagprefix="cc1" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"><title>CustomGrid Test</title></head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<asp:ScriptManager ID="ScriptManager1" runat="server"> | |
</asp:ScriptManager> | |
<cc1:CustomGrid runat="server" ID="mainCustomGrid" onitemcreated="mainCustomGrid_ItemCreated"></cc1:CustomGrid> | |
</div> | |
</form> | |
</body> | |
</html> |
Default.aspx.cs
using System; | |
using System.Collections.Generic; | |
public partial class _Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
List<TestData> GridData = new List<TestData>(); | |
for (int i = 1000; i < 1025; i++) | |
GridData.Add(new TestData { Name = "Name " + i.ToString(), Phone = "555-555-" + i.ToString() }); | |
mainCustomGrid.DataSource = GridData; | |
} | |
protected void mainCustomGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { | |
// Do work here... | |
} | |
} | |
public class TestData | |
{ | |
public string Name { get; set; } | |
public string Phone { get; set; } | |
} |
Exception
[InvalidCastException: Unable to cast object of type 'Telerik.Web.UI.GridItemEventHandler' to type 'Telerik.Web.UI.GridItemEventHandler'.]
Telerik.Web.UI.RadGrid.OnItemCreated(GridItemEventArgs e) +110
Telerik.Web.UI.RadGrid.CallOnItemCreated(GridItemEventArgs e) +39
Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +986
Telerik.Web.UI.GridTableView.CreateHeaderItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTHead thead) +126
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +980
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +802
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
Telerik.Web.UI.GridTableView.PerformSelect() +28
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
Telerik.Web.UI.GridTableView.DataBind() +368
Telerik.Web.UI.RadGrid.DataBind() +165
Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3855
Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +177
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.AddedControl(Control control, Int32 index) +265
System.Web.UI.ControlCollection.Add(Control child) +80
Company.CustomControls.CustomGrid.CreateChildControls() in C:\Data\CompositeControlGrid\TelerikTesting\CustomControls\CustomGrid.cs:28
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +84