I am trying to pass DataTable to RadGrid NeedDataSource event function and assign that DataTable to RadGrid but facing below error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0123: No overload for 'RadGrid2_NeedDataSource' matches delegate 'GridNeedDataSourceEventHandler'
Source Error:
Line 241: <telerik:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel" Skin="Vista"></telerik:RadAjaxLoadingPanel> Line 242: Line 243: <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid2" runat="server" GridLines="None" Visible="false" AllowSorting="True" AllowPaging="True" PageSize="10" Width="100%" OnNeedDataSource="RadGrid2_NeedDataSource" OnItemDataBound="RadGrid2_ItemDataBound" Skin="Metro" HeaderStyle-Font-Size="8px" PagerStyle-Font-Size="12px" CellSpacing="0"> Line 244: Line 245:
My C# code:
DataTable dt=new DataTable();
Radgrid2.NeedDataSource += new GridNeedDataSourceEventHandler((sender, e) => RadGrid2_NeedDataSource(sender, e, dt));
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e, DataTable t)
{
RadGrid2.DataSource=t;
}
ASP.NET Code:
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid2" runat="server" GridLines="None" Visible="false" AllowSorting="True" AllowPaging="True" PageSize="10" Width="100%" OnNeedDataSource="RadGrid2_NeedDataSource" OnItemDataBound="RadGrid2_ItemDataBound" Skin="Metro" HeaderStyle-Font-Size="8px" PagerStyle-Font-Size="12px" CellSpacing="0">
<ClientSettings ReorderColumnsOnClient="true" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">
<Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="2000" LoadingPanelID="RadAjaxLoadingPanel1" ItemsPerView="100"/>
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2"></Scrolling>
<Resizing AllowResizeToFit="false" AllowColumnResize="true" />
</ClientSettings>
<PagerStyle Mode="NumericPages" Height="1em"></PagerStyle>
<GroupingSettings CaseSensitive="false" />
</telerik:RadGrid>
What can be done for this? any suggestion
Start with reading the vendor documentation on this event. The handier you are trying to attach has the wrong signature, as the error message says.
Copy the proper one from the docs, remove the dynamic handier addition (you have it in the markup), get the data table inside the handler to give to the grid.