簡體   English   中英

無法從用戶控件屬性中的字符串表示形式'null'創建'System.Nullable'類型的對象

[英]Cannot create an object of type 'System.Nullable` from its string representation 'null' in user control proerty

我有這樣的用戶控件

<uc1:wucSwitchButton3States runat="server" State="true" ID="wucSwitchButton3States" />

在后面的用戶控制代碼中,我聲明了一個名為state的可空屬性

public bool? State { get; set; }

如果我將State設置為truefalse,則可以正常工作,但是如果將State設置為null

<uc1:wucSwitchButton3States runat="server" State="null" ID="wucSwitchButton3States" />

我遇到以下錯誤:

無法從其字符串表示形式'null'為'State'屬性創建'System.Nullable'...類型的對象。

我什至嘗試過State=""State="<%=null%>"但它們都沒有解決問題,您有解決問題的想法嗎?

根據CheckBox代碼,id自己沒有嘗試過,但是:

bool _state;

[TypeConverter(typeof(NullableBoolConverter))]
public bool? State
{
   get { return _state; }
   set { _state = value; RaisePropertyChanged(); }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM