下面来看下属性的表现形式
简单属性表现形式如下,大家都很熟悉
<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>(3)内镶集合属性的表现形式,如DropDownList (先不介绍,大家可看MSDN)
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>xasp:ListItem>
<asp:ListItem>xxasp:ListItem>
<asp:ListItem>xxxasp:ListItem>
asp:DropDownList>下面得好好看
1,复杂属性基本使用方法
请看我是怎么做的,关于下面看到了一些元数据,如果你不熟悉,请参考MSDN.
下面一段代码记录一个custom的信息.
1.1 定义枚举
using System;
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;
}
}
}
}1.3 呈现控件
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;
}<