0

I am trying to use ObjectDataSource for the first time with my code but in its SelectMethod I am always getting the Control as null.

ObjectDataSource

<asp:ObjectDataSource ID="objDataSourceStartAddress" runat="server" SelectMethod="GetSearchStartAddress" TypeName="TransElite.MainApplication.Booking" >
</asp:ObjectDataSource>

Control using ObjectDataSource

<telerik:RadSearchBox runat="server" ID="radtxtSearchStartAddress" EmptyMessage="Search Resolved Address" MinFilterLength="5" OnSearch="radtxtSearchStartAddress_Search" DataTextField="DisplayAddress" DataValueField="Id" DataSourceID="objDataSourceStartAddress" Width="85%">
</telerik:RadSearchBox>

SelectMethod of ObjectDataSource

public List<AddressData> GetSearchStartAddress()
{
    // Assigning collection/list to StartSearchAddress 
    var StartSearchAddress = ClientDataProvider.AddressList(radtxtSearchStartAddress.Text);

    return StartSearchAddress;
}

Kindly suggest how to use the control in SelectMethod.

DanM7
  • 2,101
  • 3
  • 25
  • 45
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Daniel Kelley Jun 14 '14 at 14:58
  • No Daniel, it is no where near to the duplicate what you are referring to. – user3300131 Jun 15 '14 at 08:50
  • I'm afraid it is. *All* NullReferenceExceptions are caused by the same problem that requires simple debugging effort to figure out. – Daniel Kelley Jun 15 '14 at 13:58
  • Daniel, i think instead of starting with an indefinite argument its better you can provide here a sample code. – user3300131 Jun 16 '14 at 05:28

2 Answers2

0

http://demos.telerik.com/aspnet-ajax/searchbox/examples/declarativedatasources/defaultcs.aspx

Here you go, some examples on using declarative datasource controls. Suche exceptions, are, however, more likely to stem from the objects and not from the control that requests them. As Daniel said - debugging is the way to go. Noone here has your custom objects, classes and application.

rdmptn
  • 4,975
  • 1
  • 12
  • 25
0

Thanks guys for your efforts. But i figured out the code which resolved issue with my code. What is concluded is you cannot use control with the method used in SelectMethod. So the other way used is using SelectParameters as following :

<asp:ObjectDataSource ID="objDataSourceStartAddress" runat="server" SelectMethod="GetSearchStartAddress" TypeName="TransElite.MainApplication.Booking">
        <SelectParameters>
            <asp:ControlParameter Name="startaddress" ControlID="radtxtSearchStartAddress" PropertyName="Text" DefaultValue="BLANKTEXT" />
        </SelectParameters>
    </asp:ObjectDataSource>

and code behind will have following code :

public List<AddressData> GetSearchStartAddress(string startaddress)
    {
        if (startaddress.Trim() == "BLANKTEXT")
            return null;


        var StartSearchAddress = ClientDataProvider.AddressListPanelCallback(startaddress);

        return StartSearchAddress;

    }