Latest web development tutorials

ASP.NET SortedList

SortedList 개체는 개체와 ArrayList를 해시 테이블 개체의 속성을 결합합니다.


예

시도 - 예

SortedList는 RadioButtonList 1

SortedList는 RadioButtonList 2

SortedList DropDownList로


SortedList 개체

SortedList 개체가 키 항목이 포함되어 / 값 쌍을 표현했다. SortedList가 자동으로 알파벳 순 또는 숫자 순으로 항목을 정렬 개체.

추가 () 메소드에 의해 SortedList에 항목을 추가 할 수 있습니다. TrimToSize () 메소드에 의해 최종 크기 SortedList를 조정합니다.

다음 코드는 mycountries라는 SortedList 개체를 생성하고, 네 가지 요소를 추가 :

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>


데이터 바인딩

SortedList 개체가 자동으로 다음과 같은 컨트롤이 텍스트와 값을 생성 할 수 있습니다 :

  • ASP :는 RadioButtonList
  • ASP : CheckBoxList
  • ASP : DropDownList로
  • ASP를 : 목록 상자

RadioButtonList 컨트롤에 데이터를 바인딩하려면 먼저 (:을 ListItem 요소 어떤 ASP를하지 않고)는 .ASPX 페이지에 RadioButtonList 컨트롤을 만듭니다

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

그 후 목록 및 RadioButtonList 컨트롤로 목록의 결합 값을 생성하기 위해 스크립트를 추가

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

서브 루틴을 실행할 때 사용자가 RadioButtonList 컨트롤의 항목을 클릭 할 때 다음 우리는, 서브 루틴을 추가합니다. 라디오 버튼을 클릭하면, 라벨은 텍스트 줄에 표시된다 :

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

데모 >>