不是说一般复杂属性没有set访问器吗?只要保证字属性有get/set就可以了,为什么复杂内部嵌套属性没有set,在页面中使用时就会报错呢?而连字符串形式的复杂属性就不能有set。
private Person person;
[Category("复杂属性")]
[Description("复杂属性")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Person Person
{
get {
if (person==null)
{
person = new Person();
}
return person; }
// set { person = value; }//这个set注释掉在页面使用时就出错
}复杂内部嵌套属性
private Person person;
[Category("复杂属性")]
[Description("复杂属性")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Person Person
{
get {
if (person==null)
{
person = new Person();
}
return person; }
// set { person = value; }//这个set注释掉在页面使用时就出错
}复杂内部嵌套属性
解决方案 »
- 求救,我脑子已经转不过弯来了!!!!
- 求救....C#+Oracle
- 如何 : 实现数据库提取图片,然后循环滚动显示图片(没有间隔)? 就象CSDN 论坛那 滚动的字条一样..
- 如何得到datalist的第一条记录?
- 大家给个建议
- 200分征求问题的答案 是关于任意文件在数据库中的存入和取出,孟子大哥各位高手请进
- 如何连接odbc数据库,错误提示如下,如何解决呢,我是新手
- rmb请人解决ASP.NET程序向MSSQL数据插入中文时显示??号
- 请各位兄弟给点建议:RadioButtonList控件与DataGrid显示不同表
- 头疼的项目,如何破?
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。
- 拼接html代码时将绑定的数据源作为参数<%#Eval("")%>总是有问题
public class Person
{
private string text;
[NotifyParentProperty(true)]
public string Text
{
get { return text; }
set { text = value; }
}
private string value;
[NotifyParentProperty(true)]
public string Value
{
get { return this.value; }
set { this.value = value; }
}
}控件代码如下:[DefaultProperty("Text")]
[ToolboxData("<{0}:InnerProperty runat=server></{0}:InnerProperty>")] public class InnerProperty : WebControl
{
private Person person;
[Category("复杂属性")]
[Description("复杂属性")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Person Person
{
get {
if (person==null)
{
person = new Person();
}
return person; }
//set { person = value; }
}页面中使用时,编译报错:
类型ServerControl1.ServerControl1中不存在类型名称"Person“
把set取消注释就可以了,就是弄不明白,这个set不是在复合属性中一般需要的吗?只要子属性有get/set就行了
{
get {
if (person==null)
{
person = new Person();
}
return person; }
//set { person = value; }
}