2012-05-01 15 views
0

SelectedIndexChanged関数に余分なパラメータを送る方法はありますか?SelectedIndexChangedで余分なパラメータを送信するにはどうすればよいですか?

<asp:RadioButtonList 
        ID="rblMeetingPlace" 
        SelectedValue = '<%# Bind("intMtgLoc") %>' 
      *OnSelectedIndexChanged = "Validate('txtMeetPlaceOther')"* 
        runat="server" 
        RepeatDirection="Horizontal" 
> 
<asp:ListItem Value="1">Workshop</asp:ListItem> 
<asp:ListItem Value="2">Service provider agency</asp:ListItem> 
<asp:ListItem Value="3">Advocacy organization</asp:ListItem> 
<asp:ListItem Value="4">Public Space</asp:ListItem> 
<asp:ListItem Value="5">Other (specify): </asp:ListItem> 
<asp:ListItem Value="" Text="" style="display: none" /> 
</asp:RadioButtonList> 
<asp:TextBox ID="txtMeetPlaceOther" Text='<%# Bind("strMtgLocOth") %>' 
runat="server" /> 

私はradiobuttonlistをいくつか持っており、「その他」が選択されている場合はテキストボックスを有効にしたいと考えています。 私はそれを可能にするために、テキストボックスのIDを送ることを考えています。

答えて

1

あなたは簡単にこの方法は、それを行うことができます。

<asp:radiobuttonlist id="rbl1" runat="server" 
    RepeatDirection="Horizontal" 
    AutopostBack="true" 
    SelectedValue='<%# Bind("intMtgLoc") %>' 
    OnselectedIndexChanged="rbl1_SelectedIndexChanged"> 
     <asp:ListItem Value="1">Workshop</asp:ListItem> 
     <asp:ListItem Value="2">Service provider agency</asp:ListItem> 
     <asp:ListItem Value="3">Advocacy organization</asp:ListItem> 
     <asp:ListItem Value="4">Public Space</asp:ListItem> 
     <asp:ListItem Value="5">Other (specify): </asp:ListItem> 
     <asp:ListItem Value="" Text="" style="display:none" /> 
     </asp:radiobuttonlist> 
<asp:textbox id="txtMeetPlaceOther" text='<%# Bind("strMtgLocOth") %>' runat="server" /> 
<asp:textbox id="TextBox1" enabled="false" runat="server"></asp:textbox> 
<asp:textbox id="TextBox2" enabled="false" runat="server"></asp:textbox> 

とコードビハインドで:コメントする

protected void rbl1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     *yourValidatorName*.Validate(); 
     if (Convert.ToInt32(rbl1.SelectedValue) == 5) 
     { 
      TextBox1.Enabled = true; 
      TextBox2.Enabled = true; 
     } 
     else 
     { 
      TextBox1.Enabled = false; 
      TextBox2.Enabled = false; 
     } 
    } 

返信:あなたはすべてのRadioButtonListsイベントハンドラのOnSelectedIndexChangedを設定する必要があり、すべての 初。ここに - rbl_SelectedIndexChanged。 は、その後の背後にあるコードで:

protected void rbl_SelectedIndexChanged(object sender, EventArgs e) 
     { 

      TextBox[] textboxes = new TextBox[] { TextBox1, TextBox2 };//all your textboxes. 

      RadioButtonList whoCallEvent = sender as RadioButtonList; 


      string last = whoCallEvent.ID.ToString().Substring(whoCallEvent.ID.ToString().Length - 1, 1);//get the last symbol of object (TextBox) ID, who call event. 
      int index = Convert.ToInt32(last); 
      if (Convert.ToInt32(whoCallEvent.SelectedValue) == 5) 
      { 
       textboxes[index - 1].Enabled = true; 
      } 
      else 
      { 
       textboxes[index - 1].Enabled = false; 
      } 
     } 

しかし、私は、これは、このようにそれを行うには、概念的に間違っていると思います。最良の方法は、自分のページにあるradioButtonListすべてに対してrbl_SelectedIndexChangedを作成することです。

+0

あなたのメソッドを使用して、自分のページにあるすべてのradioButtonListに対してrbl1_SelectedIndexChangedを作成する必要があります。 TextBoxの有効化/無効化を処理できる単一の関数を作成したい – SZT

関連する問題