グリッドビューで objectdatasource を使用しています。ODS の SelectMethod は機能していますが、希望どおりではありません。DefaultValue プロパティと関係があると確信していますが、すでに設定しようとしましたが、うまくいきませんでした。コードは次のとおりです。
<asp:ObjectDataSource ID="AppointmentsDataSource" runat="server"
TypeName="DAL"
DataObjectTypeName="DatabaseModel.Appointment"
SelectMethod="getAppointmentsfiltered">
<SelectParameters>
<asp:ControlParameter ControlID="txtCal" PropertyName="Text" Type="DateTime" Name="chosenDate" DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
Public Function getAppointmentsfiltered(chosenDate As DateTime) As IEnumerable(Of Appointment)
If String.IsNullOrEmpty(chosenDate) Then
Return GetAllAppointments()
Else
Dim appts = (From a In context.Appointments.Include("Client")
Where a.AppointmentDate.Equals(chosenDate)
Select a).ToList()
Return appts
End If
End Function
Public Function GetAllAppointments() As IEnumerable(Of DatabaseModel.Appointment)
Dim AllAppointments = (From a In context.Appointments.Include("Client")
Order By a.AppointmentDate Descending
Select a).ToList()
Return AllAppointments
End Function
私のテキストボックス:
<asp:TextBox ID="txtCal" runat="server" AutoPostBack="true" OnTextChanged="txtCal_TextChanged" Text=""></asp:TextBox>
<img id="caltrigger" alt="Click this icon to display the calendar" src="../Images/calendar-icon.png" width="18" height="20" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtCal" PopupButtonID="caltrigger">
</asp:CalendarExtender>
ご覧のとおり、日付テキスト ボックスの値が空であるため、最初にグリッドビューにすべての予定を表示したいと考えています。フィルタリングは正常に機能します。
どんな助けでも感謝します、そして私の無知を許してください、しかし私はasp.netにかなり慣れていません
編集: マークアップで 2 つの ODS を宣言し、実行時に切り替えて、この問題を処理しましたが、上記のコードが機能しなかった理由を誰かに教えていただければ幸いです。