ASP.NET SelectedIndex ਵਿਸ਼ੇਸ਼ਤਾ

ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ

SelectedIndex ਪ੍ਰਤੀਯੋਗਿਤਾ ਵਿਸ਼ੇਸ਼ਤਾ ਵਿੱਚ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ ਤਾਂ ਕਿ DropDownList ਵਿੱਚ ਚੁਣੇ ਗਏ ਆਈਟਮ ਦਾ ਸੰਖਿਆ ਨੂੰ ਲੈ ਲਿਆ ਜਾ ਸਕੇ ਜਾਂ ਸੈਟ ਕੀਤਾ ਜਾ ਸਕੇ。

ਇੰਸਟੈਂਸ

ਹੇਠ ਦਾ ਉਦਾਹਰਣ ਚੁਣੇ ਗਏ ਆਈਟਮ ਦਾ ਟੈਕਸਟ ਪ੍ਰਦਰਸ਼ਿਤ ਕਰਦਾ ਹੈ:

<script runat="Server">
Sub GetName(obj As Object, e As EventArgs)
  lbl.Text = ddList.SelectedItem.Text
End Sub
</script>
<form runat="Server">
Select a name from the list:
<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 />
Name is:
<asp:Label id="lbl" Runat="Server"/>
</form>

ਇੰਸਟੈਂਸ

DropDownList ਵਿੱਚੋਂ ਇੱਕ ਆਈਟਮ ਦਾ ਟੈਕਸਟ ਲੈ ਲਓ