asp:DropDownList 使用


<asp:DropDownList ID="DropDownList1" runat="server" onchange="return My_DropDownList1()" />

一、DropDownList后台數據綁定

1.DropDownList1.DataSource=DataSet.tables 綁定數據源。

2.DropDownList1.DataValueField="ID" 綁定主鍵。

3.DropDownList1.DataTextField=“Text” 綁定顯示的文本。

4.DropDownList1.DataBind() 綁定數據。

二、DropDownList前台JavaScript獲取選中項索引和獲取選中項文本

<script type="text/javascript">
  function My_DropDownList1(){
    var DD_TXT=$('#DropDownList1 option:selected').text(); 獲取選中項文本
    var DD_ID=$('#DropDownList1 option:selected').val(); 獲取選中項文本對應的索引,也就是我們綁定的主鍵ID

  }
</script>

三、DropDownList后台通過事件獲取文本和對應的索引值

DropDownList1.SelectedItem.Text     獲取文本

DropDownList1.SelectedItem.Value  獲取索引值

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM