![](/img/trans.png)
[英]Cannot create an object of type 'System.Object' from its string representation
[英]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设置为true或false,则可以正常工作,但是如果将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.