0

selectボタンをクリックした後、タグから選択した値を取得するにはどうすればよいですか? selectここでは、複数選択でhtml を取得します。

selTest.Value最初に選択された項目のみを返します。

    <select runat="server" id="selTest" name="selTest" data-placeholder="Choose a Country..." class="chzn-select" style="width:350px;" tabindex="4">
      <option value=""></option> 
      <option value="United States" selected="selected">United States</option> 
      <option value="Western Sahara">Western Sahara</option> 
      <option value="Yemen">Yemen</option> 
      <option value="Zambia" selected="selected">Zambia</option> 
      <option value="Zimbabwe" selected="selected">Zimbabwe</option>
    </select>

   <asp:Button ID="testBt" runat="server" OnClick="testBt_Click" Text="ds" />

コードビハインド:

protected void testBt_Click(object sender, EventArgs e)
{

}
4

2 に答える 2

0

ASP.NET ListBox を適切に使用するとItems、厳密に型指定された、およびクエリにアクセスできます。

<asp:ListBox runat="server" id="MyList" SelectionMode="Multiple">
  <asp:ListItem Value="-1"></asp:ListItem> 
  <asp:ListItem Valuealue="United States" Selected="True">United States</asp:ListItem>
  <asp:ListItem Valuealue="Western Sahara">Western Sahara</asp:ListItem> 
  <asp:ListItem Valuealue="Yemen">Yemen</asp:ListItem> 
  <asp:ListItem Valuealue="Zambia" Selected="True">Zambia</asp:ListItem> 
  <asp:ListItem Valuealue="Zimbabwe" Selected="True">Zimbabwe</asp:ListItem>
</asp:ListBox>

そして、選択した項目を取得するには (Linq を使用):

var selected = MyList.Items.Where(i => i.Selected);
于 2013-05-12T21:10:36.843 に答える