我有一个自定义 DropDownList 控件:
<cc1:CountriesControl ID="DdlCountry" TabIndex="69" runat="server" DefaultCountry="USA" OnSelectedIndexChanged="DdlCountryIndexChanged"
CssClass="DefaultDropdown" AutoPostBack="true" />
DropDownList 有一个名为 DefaultCountry 的自定义属性。如您所见,默认值设置为“美国”。但是在我的子类中, DefaultCountry 始终为空。
如何将 DefaultCountry 设置为 ASP.NET 标记中的内容?
[DefaultProperty("Text"), ToolboxData("<{0}:CountriesControl runat=server></{0}:CountriesControl>")]
public class CountriesControl : DropDownList
{
[Bindable(true), Category("Appearance"), DefaultValue("")]
private String defaultCountry;
[
Category("Behavior"),
DefaultValue(""),
Description("Sets the default country"),
NotifyParentProperty(true)
]
public String DefaultCountry
{
get
{
return defaultCountry;
}
set
{
defaultCountry = value;
}
}
public CountriesControl()
{
this.DataSource = CountriesDataSource();
this.DataTextField = "CountryName";
this.DataValueField = "Country";
this.SelectedIndex = 0;
this.DataBind();
// DefaultCountry is always null?
this.Items.Insert(0, new ListItem(this.DefaultCountry, "--"));
}
// more code here
}