Latest web development tutorials

ASP.NET ArrayList를

개별 데이터 값 항목의 컬렉션을 포함 ArrayList를 객체입니다.


예

시도 - 예

ArrayList를 DropDownList로

ArrayList에는 RadioButtonList


ArrayList를 만들기

개별 데이터 값 항목의 컬렉션을 포함 ArrayList를 객체입니다.

추가 () 메소드를 통해 ArrayList에 항목을 추가.

다음 코드는 ArrayList를 개체 이름 mycountries를 만들고 네 개의 항목을 추가 :

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
end if
end sub
</script>

기본적으로 ArrayList의 개체는 16 항목이 포함되어 있습니다. TrimToSize () 메소드에 의해 최종 크기의 ArrayList를 조정합니다 :

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
end if
end sub
</script>

정렬 () 방법으로, ArrayList를 알파벳 순서 또는 정렬 숫자 순서에있을 수 있습니다 :

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
end if
end sub
</script>

정렬 () 메서드 역 () 메서드 후, 역 정렬을 달성하기 :

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
mycountries.Reverse()
end if
end sub
</script>


ArrayList에에 바인딩 데이터

ArrayList의 목적은 자동으로 다음과 같은 컨트롤이 텍스트와 값을 생성 할 수 있습니다 :

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

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

<html>
<body>

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

</body>
</html>

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

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
rb.DataSource=mycountries
rb.DataBind()
end if
end sub
</script>

<html>
<body>

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

</body>
</html>

데모 >>

는 RadioButtonList 컨트롤의 데이터 소스 속성은 RadioButtonList 컨트롤의 데이터 소스를 정의하는 ArrayList를,로 설정되어 있습니다. RadioButtonList 컨트롤의는 RadioButtonList 컨트롤의 DataBind () 메서드는 데이터 소스를 바인딩합니다.

주 : 사용하는 컨트롤의 텍스트 및 속성 값으로서데이터 값. 값을 추가하려면 텍스트는 달리, 해시 테이블 개체 또는 SortedList 개체를 사용하십시오.