无法从asp:ObjectDataSource传递null值

时间:2015-09-16 16:34:44

标签: c# asp.net objectdatasource

下面给出的是我试图从texbox中传递日期时间值。它传递所有其他值,但它传递空值为{1/1/0001 12:00:00 AM}。我希望它传递null值得。请帮忙?

<asp:ObjectDataSource ID="Schedules" runat="server" SelectMethod="GetScheduleByDate"
        TypeName="WebUI.Code" OldValuesParameterFormatString="original_{0}">
        <SelectParameters>
            <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="TextBoxSchedules" Name="ScheduleDate" PropertyName="Text" Type="DateTime"/>
        </SelectParameters>
    </asp:ObjectDataSource>

1 个答案:

答案 0 :(得分:0)

我通过以下代码解决了同样的问题:

<asp:ObjectDataSource ID="MyDataSource" runat="server" SelectMethod="GetSomething" TypeName="MyNamespace.MyAdapterType">
    <SelectParameters>
        <asp:Parameter Name="id" Type="Object" ConvertEmptyStringToNull="True" />
        <asp:Parameter Name="enabled" Type="Object" ConvertEmptyStringToNull="True" />
    </SelectParameters>
</asp:ObjectDataSource>

方法签名

public class MyAdapterType
{
    public IEnumerable<CollectorPlugin> GetCollectorPlugin(Guid? id = null, bool? enabled = null)
    {
        //in debug mode i have here 2 null objects
        throw new NotImplementedException();
    }
}