2015-09-16 22 views
1

下面給出的是我試圖從texbox.it傳遞所有其他值,但它傳遞了空值作爲{1/1/0001 12:00:00 AM }。我想讓它傳遞null值。請幫忙?無法從asp傳遞空值:ObjectDataSource

<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> 
+4

[DATETIME](https://msdn.microsoft.com/en-us/library /system.datetime(v=vs.110).aspx)是一個結構體,在這個意義上不可空,就像一個int或一個long。也許'可空''會起作用。 – rene

+1

另一種選擇是'DateTime? myDatetime' –

+0

謝謝!我知道這個概念,但我一直沒有做到一切正確。現在我再次嘗試,它的工作原理!多謝你們! – rampantNinja

回答

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(); 
    } 
}