ویژگی SelectedIndex ASP.NET
تعریف و استفاده
ویژگی SelectedIndex برای دریافت یا تنظیم شماره آیتم انتخاب شده در DropDownList استفاده میشود.
مثال
مثال زیر متن آیتم انتخاب شده را چاپ میکند:
<script runat="Server"> Sub GetName(obj As Object, e As EventArgs) lbl.Text = ddList.SelectedItem.Text End Sub </script> <form runat="Server"> از لیست یک نام انتخاب کنید: <asp:DropDownList id="ddList" runat="Server"> <asp:ListItem Text="Peter" /> <asp:ListItem Text="Lois" /> <asp:ListItem Text="Cleveland" /> <asp:ListItem Text="Quagmire" /> <asp:ListItem Text="Joe" /> </asp:DropDownList> <asp:Button Text="Select" OnClick="GetName" Runat="Server" /> <br /> نام است: <asp:Label id="lbl" Runat="Server"/> </form>
مثال
- متن یکی از آیتمهای DropDownList را دریافت کنید