1. selectedIndex——指的是dropdownlist中選項的索引,為int,從0開始,可讀可寫
2. selectedItem——指的是選中的dropdownlist中選項,為ListItem,只讀不寫
3. selectedValue——指的是選中的dropdownlist中選項的值,為string,只讀不寫
4. selectedItem.Text——指的是選中的dropdownlist中選項的文本內容,與selectedItems的值一樣為string,可讀可寫
5. selectedItem.value——指的是選中的dropdownlist中選項的值,與selectedValue的值一樣,為string,可讀可寫
不太理解,看demo
demo
aspx文件
<div> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Value="1">北京</asp:ListItem> <asp:ListItem Value="2">上海</asp:ListItem> <asp:ListItem Value="3">廣州</asp:ListItem> </asp:DropDownList> <br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <br /> <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br /> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /> </div>
cs文件
protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "selectedIndex=" + DropDownList1.SelectedIndex; Label2.Text = "selectedItem=" + DropDownList1.SelectedItem; Label3.Text = "selectedValue=" + DropDownList1.SelectedValue; Label4.Text = "selectedItem.text=" + DropDownList1.SelectedItem.Text; Label5.Text = "selectedItem.value=" + DropDownList1.SelectedItem.Value; }
運行結果