私は以下のようにドロップダウンリストコントロールを作成するカスタムクラスを持っている:asp.net WebBrowserコントロールイベントの順序とViewStateの
public class IHGridView : System.Web.UI.WebControls.WebControl
{
private string _dataSource = "not set yet";
public string DataSource
{
get { return _dataSource; }
set { _dataSource = value; }
}
}
EDIT:
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"は、このクラスが書き込む最初の無効です。 前に "DataSource"のようなプロパティを使用したい場合は、 "OnInit" void ... どうすればいいですか?
EDIT:
protected void Button1_Click(object sender, EventArgs e)
{
IHGridViewTest2.DataSource = "fired";
}
aspxページ内のボタンが発射されたときにデータソースが設定されています。
DataSourceが設定されていますか? – millimoose
ボタンが押されたとき。私は質問を編集しました。 –