ASP.NET - ArrayList అబ్జెక్ట్

ArrayList అబ్జెక్ట్ ఒక ఏక డేటా విలువ కలిగిన ప్రతిపాదనల సమూహం ఉంటుంది.

ఇన్స్టాన్స్

ArrayList DropDownList

ArrayList RadioButtonList

ArrayList సృష్టించండి

ArrayList అబ్జెక్ట్ ఒక ఏక డేటా విలువ కలిగిన ప్రతిపాదనల సమూహం ఉంటుంది.

Add() మంథ్రం ద్వారా ArrayList కు ప్రతిపాదనలను జోడించండి.

ఈ కోడ్ ఒక కొత్త ArrayList అబ్జెక్ట్ సృష్టించి, మొక్కటికి నామకరణం చేసి నాలుగు ప్రతిపాదనలను జోడించింది:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  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("China")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
end if
end sub
</script>

Sort() మంథ్రం ద్వారా, ArrayList అక్షరరూపం లేదా సంఖ్యాక్రమం ప్రకారం క్రమబద్ధం చేయగలదు:

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

సరికొత్త క్రమబద్ధిని అమలు చేయడానికి, Sort() మంథ్రం తర్వాత Reverse() మంథ్రాన్ని ఆపాదించండి:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("China")
  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:Listbox

డేటాను రేడియోబటన్ లిస్ట్ కంట్రోల్కు బైండ్ చేయడానికి, ముందు ఒక .aspx పేజీలో రేడియోబటన్ లిస్ట్ కంట్రోల్ సృష్టించండి (లక్ష్యంగా ఏ అస్ప్:లిస్టింగ్ అంశం లేదు):

<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("China")
  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 కంట్రోల్ యొక్క DataSource అంశం ఈ ArrayList కు అమర్చబడింది, ఇది RadioButtonList కంట్రోల్ యొక్క డేటా స్రోతాన్ని నిర్వచిస్తుంది. RadioButtonList కంట్రోల్ యొక్క DataBind() పద్ధతి RadioButtonList కంట్రోల్ ని డేటా స్రోతంతో బంధిస్తుంది.

పేర్కొనుట:డేటా విలువను కంట్రోల్ యొక్క Text మరియు Value అంశాలుగా ఉపయోగించండి. Text కంటే వేరే Value జోడించడానికి, హేష్‌టేబుల్ అంశాన్ని లేదా సార్టెడ్‌లిస్ట్ అంశాన్ని ఉపయోగించవచ్చు.