0

その値に基づいてテキストボックスの値を入力するドロップダウンボックスがあります。変更されたときに発火しますが、ページロード時には発火しません。ページの読み込み時に起動するにはどうすればよいですか?

   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {     
   TextBox3.Text = DropDownList1.SelectedValue;
        TextBox12.Text = DropDownList1.SelectedValue;
        TextBox21.Text = DropDownList1.SelectedValue;

     //etc
4

3 に答える 3

2

ティム・シュメルターのコメントは、まさにその通りです。

// Wire up to the page load event
protected void Page_Load(object sender, System.EventArgs e)
{
   updateTextBoxes();
}

// Wire up to the select index-changed event
protected void DropDownList1_SelectIndexChanged( object sender, EventArgs e )
{
    updateTextBoxes();
}


// your workhorse method
protected void updateTextBoxes()
{
   TextBox3.Text  = DropDownList1.SelectedValue;
   TextBox12.Text = DropDownList1.SelectedValue;
   TextBox21.Text = DropDownList1.SelectedValue;

   // etc.
}
于 2012-09-05T20:07:26.010 に答える
1

ページの読み込み時に自動的に呼び出されることはありません。「手動で」呼び出す必要があります。

 void Page_Load(object sender, System.EventArgs e) {

     // ....

     DropDownList1_SelectedIndexChanged(DropDownList1, e);

 }
于 2012-09-05T20:06:41.267 に答える
0

SelectedIndexChangedユーザー主導の変更に応じて起動します。割り当てロジックを別のメソッドに移動しPage_Load、イベント ハンドラーから手動で呼び出します。

于 2012-09-05T19:54:56.457 に答える