我在我的 gridview 中使用 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>
如您所见,我最初想在 gridview 中查看所有约会,因为我的日期文本框的值为空。过滤工作正常。
任何帮助将不胜感激,并原谅我的无知,但我对 asp.net 还很陌生
编辑:我最终在标记中声明了两个 ODS 并在运行时切换,这解决了这个问题,但如果有人能告诉我为什么上面的代码不起作用,我会很感激。