【发布时间】:2011-10-19 13:37:11
【问题描述】:
我有一个创建下拉列表控件的自定义类,如下所示:
public class IHGridView : System.Web.UI.WebControls.WebControl
{
private string _dataSource = "not set yet";
public string DataSource
{
get { return _dataSource; }
set { _dataSource = value; }
}
}
编辑:
protected override void OnInit(EventArgs e)
{
// VIewState is alive. When I select an option and submit, after postback it's selected value is the one I selected.
this.Controls.Add(_dropDownList);
}
或
protected override void CreateChildControls()
{
// VIewState is dead. When I select an option and submit, after postback it's selected value is the default one.
this.Controls.Add(_dropDownList);
}
所以,现在我想出我必须在“OnInit”void 中添加控件的结果。 但是,这个“OnInit”是这个类写入的第一个 void。 如果我以前想使用像“DataSource”这样的属性,“OnInit”无效...... 我该怎么做?
编辑:
protected void Button1_Click(object sender, EventArgs e)
{
IHGridViewTest2.DataSource = "fired";
}
在触发 aspx 页面中的按钮时设置数据源。
【问题讨论】:
-
触发按钮时。我编辑了问题。