"objectdatasource selecting method can't 'see' any other control's values" Code Answer


It sounds like you are expecting code in your ObjectDataSource to have access to your Page object and its children. That is not how it works generally speaking. The code in your ObjectDataSource needs to stand on its own, which means if you need to filter your SQL SELECT using a couple of dates, those dates should be sent as parameters.

If you can post your ObjectDataSource markup and the Class code for your DAL object, I can provide a specific example.

However the general answer to your question can be found in this article:

MSDN: Using Parameters with the ObjectDataSource Control

The problem with using the current Page Class for ObjectDataSource.TypeName is that every time ObjectDataSource binds, it creates a new instance of the Class to work with (with caveats, but that's not important here). This is why you cannot read control values but you can read session. This is why you can't rely on directly accessing items on your page from within your SelectMethod. You need to pass the query parameters in as parameters of the SelectMethod.

It looks like you already have an Class called Sql with (shared?) methods that are set up to do the data access. That is the class your creditRateObjectDataSource.TypeName should reference. Then have creditRateObjectDataSource.SelectMethod be sql.GetCreditRateHistoryPagedRecords, similar to this example:

<asp:ObjectDataSource ID="creditRateObjectDataSource" runat="server" EnablePaging="true"
    TypeName="AegonSVS.Restricted.sql" SelectMethod="GetCreditRateHistoryPagedRecords"
    StartRowIndexParameterName="startRowIndex" MaximumRowsParameterName="maximumRows"
    SortParameterName="sortExpression" SelectCountMethod="CreditRateSelectCountMethod">
        <asp:ControlParameter Name="startDateTime" ControlID="startDatePicker" PropertyName="SelectedDate"
            DbType="DateTime" />
        <asp:ControlParameter Name="endDateTime" ControlID="endDatePicker" PropertyName="SelectedDate"
            DbType="DateTime" />
        <asp:Parameter Name="contractId" DefaultValue="1" DbType="Int32" />
By James Allardice on June 4 2022

Answers related to “objectdatasource selecting method can't 'see' any other control's values”

Only authorized users can answer the Search term. Please sign in first, or register a free account.