I don't even know how to state this clearly, and there's too much code to paste it all in here.
Let me start off with a general description and maybe it'll ring a bell. I have a DataGrid which uses an ObjectDataSource. The ObjectDataSource uses a SelectMethod that calls another method due to the fact that two datepickers are required to filter the results.
When the SelectMethod fires, though, the datepickers are always null.
A related issue is that a button is required to cause the ObjectDataSource to Select and use the two datepicker values which doesn't work at all. It's as if the ObjectDataSource doesn't consult the GridView for the starting index, etc.
If anyone knows of an example of something like this setup (GridView, Date controls, button, ObjectDataSource) that would be great.
Edit: Here's 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();
}
}