我正在使用一个带有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并在运行时切换,这解决了这个问题但是如果有人能告诉我为什么上面的代码不起作用我会很感激。