The ObjectDataSource selection method cannot "see" any other control values.

I don’t even know how to state it clearly, and there is too much code to insert it all here.

Let me start with a general description and perhaps this will cause a call. I have a DataGrid that uses an ObjectDataSource object. The ObjectDataSource object uses the SelectMethod method, which calls another method because it requires two date pickers to filter the results.

When SelectMethod is triggered, datepickers are always zero.

A related problem is that to call the ObjectDataSource object, you need to select the button and use two date picker values ​​that do not work at all. As if the ObjectDataSource is not accessing the GridView for the starting index, etc.

If anyone knows an example of something like this setting (GridView, Date controls, button, ObjectDataSource), that would be great.

Edit: Here is the code.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

   <asp:Label ID="Label39" CssClass="txtSelect" runat="server" Text="Start Date" />
   <cc1:datepicker ID="startDatePicker" runat="server" Width="70px" PaneWidth="150px" SelectedDate="1/1/2000">
      <panetablestyle bordercolor="#707070" borderwidth="1px" borderstyle="Solid" />
      <paneheaderstyle backcolor="#0099FF" />
      <titlestyle forecolor="White" font-bold="true" />
      <nextprevmonthstyle forecolor="White" font-bold="true" />
      <nextprevyearstyle forecolor="#E0E0E0" font-bold="true" />
      <dayheaderstyle backcolor="#E8E8E8" />
      <todaystyle backcolor="#FFFFCC" forecolor="#000000" font-underline="false" bordercolor="#FFCC99" />
      <alternatemonthstyle backcolor="#F0F0F0" forecolor="#707070" font-underline="false" />
      <monthstyle backcolor="" forecolor="#000000" font-underline="false" />
   </cc1:datepicker>

   <asp:Label ID="Label5" CssClass="txtSelect" runat="server" Text="End Date" />
   <cc1:datepicker ID="endDatePicker" runat="server" Width="70px" PaneWidth="150px" SelectedDate="1/1/2020">
      <panetablestyle bordercolor="#707070" borderwidth="1px" borderstyle="Solid" />
      <paneheaderstyle backcolor="#0099FF" />
      <titlestyle forecolor="White" font-bold="true" />
      <nextprevmonthstyle forecolor="White" font-bold="true" />
      <nextprevyearstyle forecolor="#E0E0E0" font-bold="true" />
      <dayheaderstyle backcolor="#E8E8E8" />
      <todaystyle backcolor="#FFFFCC" forecolor="#000000" font-underline="false" bordercolor="#FFCC99" />
      <alternatemonthstyle backcolor="#F0F0F0" forecolor="#707070" font-underline="false" />
      <monthstyle backcolor="" forecolor="#000000" font-underline="false" />
   </cc1:datepicker>

   <asp:Button ID="RetrieveButton" runat="server" Text="Retrieve" OnClick="RetrieveButton_Click" />

   <asp:GridView ID="creditRateGridView" runat="server"
                 DataSourceID="creditRateObjectDataSource"
                 AllowPaging="true"
                 AllowSorting="true"
                 PageSize="10" 
                 Width="900"
                 AutoGenerateColumns="False" 
                 DataKeyNames="EFFECTIVE_DATE"
                 GridLines="Both"
                 EnableSortingAndPagingCallbacks="true">
      <Columns>
         <asp:BoundField   DataField="EFFECTIVE_DATE" HeaderText="Effective Date" 
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True" 
                           SortExpression="EFFECTIVE_DATE" DataFormatString="{0:d}" />
         <asp:BoundField   DataField="REFERENCE_DATE" HeaderText="Reference Date" 
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True" 
                           SortExpression="REFERENCE_DATE" DataFormatString="{0:d}" />
         <asp:BoundField   DataField="GROSS_CREDIT_USED_RATE" HeaderText="Credit Rate" 
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True" 
                           SortExpression="GROSS_CREDIT_USED_RATE" DataFormatString="{0:p}" />
         <asp:BoundField   DataField="ANNUALIZED_YIELD_ACTUAL_AVERAGE_RATE" HeaderText="Yield" 
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True"
                           SortExpression="ANNUALIZED_YIELD_ACTUAL_AVERAGE_RATE" DataFormatString="{0:p}" />
         <asp:BoundField   DataField="DURATION_USED_YEAR" HeaderText="Duration"
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True"
                           SortExpression="DURATION_USED_YEAR" DataFormatString="{0:n2}" />
         <asp:BoundField   DataField="BOOK_VALUE_USED_AMOUNT" HeaderText="Book Value"
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True"
                           SortExpression="BOOK_VALUE_USED_AMOUNT" DataFormatString="{0:c}" />
         <asp:BoundField   DataField="MARKET_VALUE_USED_AMOUNT" HeaderText="Market Value" 
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True"
                           SortExpression="MARKET_VALUE_USED_AMOUNT" DataFormatString="{0:c}" />
         <asp:BoundField   DataField="MV_BV_RATE" HeaderText="MV/BV Ratio"
                           ItemStyle-HorizontalAlign="Right" ReadOnly="True"
                           SortExpression="MV_BV_RATE" DataFormatString="{0:p}" />
      </Columns>
      <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />
      <PagerStyle HorizontalAlign="Center" />
   </asp:GridView>

   <asp:ObjectDataSource ID="creditRateObjectDataSource" runat="server"
                         EnablePaging="true"
                         TypeName="AegonSVS.Restricted.CreditRateHistory"
                         SelectMethod="CreditRateSelectMethod" 
                         StartRowIndexParameterName="startRowIndex"
                         MaximumRowsParameterName="maximumRows"
                         SortParameterName="sortExpression"
                         SelectCountMethod="CreditRateSelectCountMethod" />

</asp:Content>


public partial class CreditRateHistory : System.Web.UI.Page
   {
      private const int contractId = 1;

      protected void Page_Load(object sender, EventArgs e)
      {
         Session.Add("startDateTime", startDatePicker.SelectedDate);
         Session.Add("endDateTime", endDatePicker.SelectedDate);
      }

      public DataTable CreditRateSelectMethod(int startRowIndex, int maximumRows, string sortExpression)
      {
         var startDateTime = (DateTime)Session["startDateTime"];
         var endDateTime = (DateTime)Session["endDateTime"];

         DataTable dataTable =  Sql.GetCreditRateHistoryPagedRecords(startDateTime,
                                                     endDateTime,
                                                     contractId,
                                                     startRowIndex,
                                                     maximumRows,
                                                     sortExpression,
                                                     null);
         return dataTable;
      }

      public int CreditRateSelectCountMethod()
      {
         var startDateTime = (DateTime)Session["startDateTime"];
         var endDateTime = (DateTime)Session["endDateTime"];

         return Sql.GetCreditRateRowCount(startDateTime,
                                          endDateTime,
                                          contractId,
                                          null);
      }

      protected void RetrieveButton_Click(object sender, EventArgs e)
      {
         // So something with this return? How?
         IEnumerable dataSource = creditRateObjectDataSource.Select();
         creditRateGridView.DataBind();
      }

   }
+3
source share
1 answer

It looks like you expect the code in yours ObjectDataSourceto have access to your object and its child objects. This is not how it works at all. The code in the ObjectDataSource must stand by itself, which means that if you need to filter SQL SELECT with a pair of dates, these dates must be sent as parameters.

If you can post ObjectDataSource markup and class code for your DAL object, I can provide a concrete example.

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

MSDN: ObjectDataSource


Page ObjectDataSource.TypeName , , ObjectDataSource , ( , ). , . SelectMethod. SelectMethod.

, Sql (shared?), . , creditRateObjectDataSource.TypeName . creditRateObjectDataSource.SelectMethod be sql.GetCreditRateHistoryPagedRecords, :

<asp:ObjectDataSource ID="creditRateObjectDataSource" runat="server" EnablePaging="true"
    TypeName="AegonSVS.Restricted.sql" SelectMethod="GetCreditRateHistoryPagedRecords"
    StartRowIndexParameterName="startRowIndex" MaximumRowsParameterName="maximumRows"
    SortParameterName="sortExpression" SelectCountMethod="CreditRateSelectCountMethod">
    <SelectParameters>
        <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" />
    </SelectParameters>
</asp:ObjectDataSource>
+4

All Articles