this is my first time using OnNeedDataSource. I've followed the sample codes within the demo to create a code-behind on the C# file. The Event on the code behind fails to fire. the following was my error message.
Compiler Error Message: CS1061: 'ASP.wellvent_aspx' does not contain a definition for 'RadGrid1_NeedDataSource' and no extension method 'RadGrid1_NeedDataSource' accepting a first argument of type 'ASP.wellvent_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
|
This is the first part of my aspx file
<
telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="False" runat="server"
AllowPaging="True" AllowSorting="True"
OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemDataBound="OnItemDataBoundHandler"
AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
ShowStatusBar="True" AllowFilteringByColumn="True" CellSpacing="0" EnableAJAX="True">
<MasterTableView ShowFooter="false" DataKeyNames="ResultsID" EditMode="InPlace" CommandItemDisplay="TopAndBottom">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
HeaderText="Edit" HeaderStyle-Width="25px" UpdateText="Update">
<HeaderStyle Width="25px" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn FilterControlAltText="Filter Delete column"
HeaderText="Delete" HeaderStyle-Width="25px" Text="Delete" UniqueName="DeleteColumn">
<HeaderStyle Width="25px" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
</telerik:GridButtonColumn>
<telerik:GridTemplateColumn UniqueName="AreaName" HeaderText="Area"
SortExpression="AreaName" ItemStyle-Width="150px">
<FooterTemplate>
Template footer
</FooterTemplate>
<FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" />
<ItemTemplate>
<%
#DataBinder.Eval(Container.DataItem, "AreaName")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="AreaName"
OnItemsRequested="RadComboBox1_ItemsRequested" DataValueField="ID" AutoPostBack="true"
HighlightTemplatedItems="true" Height="140px" Width="100px" DropDownWidth="120px"
OnSelectedIndexChanged="ComboBox1_OnSelectedIndexChangedHandler">
<ItemTemplate>
<%# DataBinder.Eval(Container, "Text")%>
</ItemTemplate>
</telerik:RadComboBox>
</EditItemTemplate>
<HeaderStyle Width="100px" />
<ItemStyle Width="100px"></ItemStyle>
</telerik:GridTemplateColumn>
This is the first part of my C# code private void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
9 Answers, 1 is accepted

I cannot reproduce the issue at my end. Make sure that you have attached the event properly. Here is the sample code that I tried by attaching NeedDataSource event which worked as expected.
aspx:
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
AutoGenerateColumns
=
"False"
onneeddatasource
=
"RadGrid1_NeedDataSource"
>
</
telerik:RadGrid
>
protected
void
RadGrid1_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
SqlConnection con2 =
new
SqlConnection(WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString3"
].ConnectionString);
SqlCommand cmd =
new
SqlCommand(
"SELECT * FROM [Employee]"
, con2);
SqlDataAdapter ad =
new
SqlDataAdapter(cmd);
DataSet ds =
new
DataSet();
ad.Fill(ds);
RadGrid2.DataSource = ds;
}
Thanks,
Princy.

<telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="False" runat="server"AllowPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="OnItemDataBoundHandler" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
ShowStatusBar="True" AllowFilteringByColumn="True" CellSpacing="0" EnableAJAX="True">
private void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e){

Remove the event from code behind and from design mode you should generate again this event,( Indesign mode : Doubleclick on Your grid)
And then bind your datasource to radgrid inside this method.
let me know if any concern.
Thanks,
Jayesh Goyani


Thanks CurtRadGrid1_NeedDataSource
Note that if you attaching the NeedDataSource event from the markup as it is shown below the access modifier should be protected in order to be accessed by derived class:
Mark-Up
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e){
Additionally make sure you are registering the Telerik controls on your page. You could globally register it by applying the following code in your web.config file:
<
pages
>
<
controls
>
<
add
tagPrefix
=
"telerik"
namespace
=
"Telerik.Web.UI"
assembly
=
"Telerik.Web.UI"
/>
</
controls
>
</
pages
>
Kind regards,
Kostadin
the Telerik team

CS1061: 'ASP.administration_facilities_aspx' does not contain a definition for 'gridFacility_NeedDataSource' and no extension method 'gridFacility_NeedDataSource' accepting a first argument of type 'ASP.administration_facilities_aspx' could be found (are you missing a using directive or an assembly reference?)
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" height="200px" width="300px">
<telerik:RadGrid ID="gridFacility" runat="server" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None"
onneeddatasource="gridFacility_NeedDataSource" >
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" DataKeyNames="FacilityId"
InsertItemPageIndexAction="ShowItemOnCurrentPage">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="Delete this facility?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="160px"
ConfirmDialogWidth="250px">
</telerik:GridButtonColumn>
<telerik:GridTemplateColumn DataField="FacilityID" HeaderText="FacilityID" UniqueName="FacilityID"
Visible="true">
<ItemTemplate>
<asp:Label ID="Label1" Text='<%# Eval( "FacilityId" ) %>' runat="server"></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind( "FacilityId" ) %>' Width="150px">
</telerik:RadTextBox>
<asp:RegularExpressionValidator ID="regexpName" runat="server" ErrorMessage="*Enter ID with exactly 5 letters."
ControlToValidate="RadTextBox1" ForeColor="Red" Display="Dynamic" ValidationExpression="^[a-z,A-Z]{5}">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="RadTextBox1"
ForeColor="Red" Text="*This field is required" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
</InsertItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="RadTextBox2" runat="server" Text='<%# Eval( "FacilityId" ) %>'
ReadOnly="true" Width="150px">
</telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Group" HeaderText="Group" UniqueName="Group">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Account" HeaderText="Account" UniqueName="Account">
<ColumnValidationSettings EnableRequiredFieldValidation="true">
<RequiredFieldValidator ForeColor="Red" Text="*This field is required"></RequiredFieldValidator>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FacilityIdentifier" HeaderText="Acronym" UniqueName="FacilityIdentifier">
<ColumnValidationSettings EnableRequiredFieldValidation="true">
<RequiredFieldValidator ForeColor="Red" Text="*This field is required"></RequiredFieldValidator>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
<ColumnValidationSettings EnableRequiredFieldValidation="true">
<RequiredFieldValidator ForeColor="Red" Text="*This field is required"></RequiredFieldValidator>
</ColumnValidationSettings>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Created" HeaderText="Created" UniqueName="Created"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Modified" HeaderText="Modified" UniqueName="Modified"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ModifiedBy" HeaderText="ModifiedBy" UniqueName="ModifiedBy"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
Code Behind:protected void gridFacility_NeedDataSource( object sender,
GridNeedDataSourceEventArgs e )
{
int pageNumber = CurrentPageNumber;
facilityGroupEdit.Cancel();
facilityEdit.Cancel();
gvResults.SelectedIndex = -1;
int groupId = GetGroupCriteria( true );
bool activeOnly = GetActiveOnly( true );
string filter = GetFilter( true );
List<FacilitySearchResult> results = BusinessProvider.ReadFacilities( groupId, activeOnly, filter, pageNumber );
gridFacility.DataSource = results;
}
Could you please confirm that you are registering the Telerik controls on your page? You could register them by using the following code snippet on the page.
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
Additionally you could check out the following help topic which describes how to clear the temporary asp.net files.
Regards,
Kostadin
Telerik

I wound up removing all the changes, and rewiring the Telerik controls.
This resolved the issue, but not certian as to what was wrong.