求指教DropDownList的
DropDownList1.SelectedIndex
DropDownList1.SelectedValue
DropDownList1.SelectedItem
各是什么东西?怎么用?
DropDownList1.SelectedIndex
DropDownList1.SelectedValue
DropDownList1.SelectedItem
各是什么东西?怎么用?
调试欢乐多
DropDownList1.SelectedValue //选择项的值
DropDownList1.SelectedItem //获得选择的项你试试都得到什么不就知道了
DropDownList1.SelectedValue //选择项的值
DropDownList1.SelectedItem //获得选择的项
DropDownList1.SelectedValue 选中项的Value属性
DropDownList1.SelectedItem 选中的项,一般包含Text和Value2个属性
DropDownList1.SelectedValue //选择项的value值
DropDownList1.SelectedItem //选择项的text值
<asp:DropDownListID="d1" runat="server">
<asp:ListItemText="AAAA" Value="a"></asp:ListItem>
<asp:ListItemText="BBBB" Value="b"></asp:ListItem>
<asp:ListItemText="CCCC" Value="c"></asp:ListItem>
</asp:DropDownList>DropDownList1.SelectedIndex的用法:
d1.Items[di.SelectedIndex]等于当前的选中项,SelectedIndex意为当前选中的索引,它可能的值为{0,1,2},d1.Items[0]则表示选中项是"AAAA"DropDownList1.SelectedValue的用法:
拿到当前选中项的Value值,如果选中项是"AAAA",那么d1.SelectedValue等于"a"。DropDownList1.SelectedItem的用法:
拿到当前的选中项,如果选中项为"AAAA",那么d1.SelectedItem.Text就是"AAAA",d1.SelectedItem.Value就是"a"。d1.SelectedItem.Value = d1.SelectedValue = d1.Items[d1.SelectedIndex].Value