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

OnNeedDataSource event fail to fire

9 Answers 435 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 08 Aug 2011, 05:22 AM
Hi,

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:

Line 44:                    </telerik:RadAjaxManager>
Line 45: 
Line 46: <telerik:RadGrid ID="RadGrid1" GridLines="None" AutoGenerateColumns="False" runat="server" Line 47:                       AllowPaging="True" AllowSorting="True" 
Line 48:                       OnNeedDataSource="RadGrid1_NeedDataSource" 


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

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Aug 2011, 05:35 AM
Hello Minh,

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>
C#:
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.
0
Minh
Top achievements
Rank 1
answered on 08 Aug 2011, 05:56 AM
I don't understand...it is still failing. I've also looked at the examples. Everything seems fine...It never reaches the code behind 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">

 

 

 

private void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e){

 

0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Aug 2011, 06:01 AM
Hello,

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
0
Sharon
Top achievements
Rank 1
answered on 07 Feb 2013, 03:01 PM
I had the exact same problem and Jayesh's solution worked! Thanks.
0
Curt
Top achievements
Rank 1
answered on 09 Apr 2013, 02:28 PM
This is not working for me. I have repeatedly deleted the RadGrid1_NeedDataSource and added it back by double clicking the grid in design view. Everytime I get the same error saying it doesn't have a definition for RadGrid1. Please help!

Thanks CurtRadGrid1_NeedDataSource

0
Kostadin
Telerik team
answered on 12 Apr 2013, 08:07 AM
Hello Curt,

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">
C#:
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
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 their blog feed now.
0
Gary
Top achievements
Rank 1
answered on 07 Aug 2013, 01:54 PM
I'm having the same issue, however, Jayesh's resolution does not work.  I've removed the reference to my function, I've added it by double clicking, I've removed the grid, and started over, but keep getting an error stating it is not found.

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;
        }
0
Kostadin
Telerik team
answered on 12 Aug 2013, 07:13 AM
Hi Gary,

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
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.
0
Gary
Top achievements
Rank 1
answered on 12 Aug 2013, 12:39 PM
It was registered in the web.config.
I wound up removing all the changes, and rewiring the Telerik controls.
This resolved the issue, but not certian as to what was wrong.
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Minh
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Sharon
Top achievements
Rank 1
Curt
Top achievements
Rank 1
Kostadin
Telerik team
Gary
Top achievements
Rank 1
Share this question
or