HtmlSelect.Value 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤에서 HtmlSelect 선택한 항목의 값을 가져오거나 컨트롤의 속성을 지정된 값이 있는 목록의 첫 번째 항목 인덱스로 설정합니다 SelectedIndex .
public:
property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public string Value { get; set; }
member this.Value : string with get, set
Public Property Value As String
속성 값
컨트롤에서 선택한 항목의 값입니다 HtmlSelect . 컨트롤 Empty 에서 선택된 항목이 없으면 반환됩니다.
예외
속성이 Value 컨트롤의 항목 수보다 크거나 보다 -1작은 항목으로 HtmlSelect 설정되었습니다.
예제
다음 코드 예제에서는 컨트롤에서 Value 선택한 항목 HtmlSelect 의 값을 가져오기 위해 속성을 사용 하는 방법을 보여 줍니다.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect Example </title>
<script runat="server">
void Button_Click (Object sender, EventArgs e)
{
Label1.Text = "You selected the item with index number " +
Select1.SelectedIndex.ToString() +
" and contains the value " +
Select1.Value + ".";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlSelect Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
runat="server">
<option value="Text for Item 1" selected="selected"> Item 1 </option>
<option value="Text for Item 2"> Item 2 </option>
<option value="Text for Item 3"> Item 3 </option>
<option value="Text for Item 4"> Item 4 </option>
<option value="Text for Item 5"> Item 5 </option>
<option value="Text for Item 6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
onserverclick="Button_Click"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect Example </title>
<script runat="server">
Sub Button_Click (sender As Object, e As EventArgs)
Label1.Text = "You selected the item with index number " & _
Select1.SelectedIndex.ToString() & _
" and contains the value " & _
Select1.Value & "."
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlSelect Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
runat="server">
<option value="Text for Item 1" selected="selected"> Item 1 </option>
<option value="Text for Item 2"> Item 2 </option>
<option value="Text for Item 3"> Item 3 </option>
<option value="Text for Item 4"> Item 4 </option>
<option value="Text for Item 5"> Item 5 </option>
<option value="Text for Item 6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
onserverclick="Button_Click"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
</form>
</body>
</html>
설명
이 Value 속성은 일반적으로 속성에서 참조 SelectedIndex 하는 항목의 값을 가져오는 데 사용됩니다.
메모
컨트롤 String.Empty 에서 선택된 항목이 없으면 반환됩니다.
이 속성을 값으로 설정하면 해당 값 SelectedIndex 이 포함된 목록의 첫 번째 항목 인덱스로 속성이 업데이트됩니다. 일치하는 값을 찾을 SelectedIndex 수 없으면 속성은 변경되지 않은 상태로 유지됩니다.