<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 獲取索引值
