dropdownlistvalueselected.aspx

来自「asp.net技术内幕的书配源码」· ASPX 代码 · 共 63 行

ASPX
63
字号
<%@ Page Language="C#"%>

<script runat=server>

void Button_Click(Object sender , EventArgs e) 
{
  lblSelectedIndex.Text = dropCategory.SelectedIndex.ToString();
  lblSelectedText.Text = dropCategory.SelectedItem.Text.ToString();
  lblSelectedValue.Text = dropCategory.SelectedItem.Value.ToString();
}

</Script>

<html>
<head><title>DropDownListValueSelected.aspx</title></head>
<body>

<form Runat="Server">

<asp:DropDownList
  ID="dropCategory"
  Runat="Server">
  <asp:ListItem
    Text="Country Music"
    Value="country" />
  <asp:ListItem
    Text="Rock Music"
    Value="rock"
    Selected="True"/>
  <asp:ListItem
    Text="Classical Music"
    Value="classic" />
</asp:DropDownList>

<asp:Button
  Text="Select Category!"
  OnClick="Button_Click"
  Runat="Server" />

<hr>

Selected Index:
<asp:Label
  ID="lblSelectedIndex"
  Runat="Server" />

<p>
Selected Text:

<asp:Label
  ID="lblSelectedText"
  Runat="Server" />

<p>
Selected Value:
<asp:Label
  ID="lblSelectedValue"
  Runat="Server" />

</form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?