我们根据属性的不同表现形式,把其区分为简单属性和复杂属性
下面来看下属性的表现形式
简单属性表现形式如下,大家都很熟悉
属性中含有子属性,称之为复杂对象,如Font属性
复杂属性的表现形式如下,
(1)连字符的表现形式
(2)内镶属性的表现形式,如定义样式
(3)内镶集合属性的表现形式,如DropDownList (先不介绍,大家可看MSDN)
下面得好好看
1,复杂属性基本使用方法
请看我是怎么做的,关于下面看到了一些 元数据,如果你不熟悉,请参考MSDN.
下面一段代码记录一个custom的信息.
1.1 定义枚举
1.2定义复杂属性
1.3 呈现控件
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
namespace CustomComponents
{
public class Custom: Control
{
private String name = null;
Address address = new Address();
private Metier metier;
private int age = 0;
属性#region 属性
[Description("年龄")]
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
[Description("姓名")]
public String Name
{
get
{
return name;
}
set
{
name = value;
}
}
[Description("职业")]
public Metier CustomMetier
{
get
{
return metier;
}
set
{
metier = value;
}<
下面来看下属性的表现形式
简单属性表现形式如下,大家都很熟悉
<
asp:TextBox
ID
="TextBox1"
Text
="textbox控件"
runat
="server"
>
asp:TextBox
>
属性中含有子属性,称之为复杂对象,如Font属性
复杂属性的表现形式如下,
(1)连字符的表现形式
<
asp:TextBox
ID
="TextBox1"
Text
="textbox控件"
runat
="server"
Font-Bold
="True"
>
asp:TextBox
>
(2)内镶属性的表现形式,如定义样式
<
asp:DataList
ID
="DataList1"
runat
="server"
>
< SelectedItemStyle />
< EditItemStyle />
asp:DataList >
< SelectedItemStyle />
< EditItemStyle />
asp:DataList >
(3)内镶集合属性的表现形式,如DropDownList (先不介绍,大家可看MSDN)
<
asp:DropDownList
ID
="DropDownList1"
runat
="server"
>
< asp:ListItem > x asp:ListItem >
< asp:ListItem > xx asp:ListItem >
< asp:ListItem > xxx asp:ListItem >
asp:DropDownList >
< asp:ListItem > x asp:ListItem >
< asp:ListItem > xx asp:ListItem >
< asp:ListItem > xxx asp:ListItem >
asp:DropDownList >
下面得好好看
1,复杂属性基本使用方法
请看我是怎么做的,关于下面看到了一些 元数据,如果你不熟悉,请参考MSDN.
下面一段代码记录一个custom的信息.
1.1 定义枚举
using
System;
namespace CustomComponents
{
/**////
/// 职业
///
public enum Metier
{
教师,程序员,作家
}
}
namespace CustomComponents
{
/**////
/// 职业
///
public enum Metier
{
教师,程序员,作家
}
}
1.2定义复杂属性
using
System;
using System.ComponentModel;
namespace CustomComponents
{
/**////
/// 地址集合
///
public class Address
{
private String street = null;
private String city = null;
private String state = null;
private String zip = null;
public String Street
{
get
{
return street;
}
set
{
street = value;
}
}
public String City
{
get
{
return city;
}
set
{
city = value;
}
}
public String State
{
get
{
return state;
}
set
{
state = value;
}
}
public String Zip
{
get
{
return zip;
}
set
{
zip = value;
}
}
}
}
using System.ComponentModel;
namespace CustomComponents
{
/**////
/// 地址集合
///
public class Address
{
private String street = null;
private String city = null;
private String state = null;
private String zip = null;
public String Street
{
get
{
return street;
}
set
{
street = value;
}
}
public String City
{
get
{
return city;
}
set
{
city = value;
}
}
public String State
{
get
{
return state;
}
set
{
state = value;
}
}
public String Zip
{
get
{
return zip;
}
set
{
zip = value;
}
}
}
}
1.3 呈现控件
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
namespace CustomComponents
{
public class Custom: Control
{
private String name = null;
Address address = new Address();
private Metier metier;
private int age = 0;
属性#region 属性
[Description("年龄")]
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
[Description("姓名")]
public String Name
{
get
{
return name;
}
set
{
name = value;
}
}
[Description("职业")]
public Metier CustomMetier
{
get
{
return metier;
}
set
{
metier = value;
}<
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-402613/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12639172/viewspace-402613/