ASP.NET - SortedList ఆబ్జెక్ట్
- ముందు పేజీ వెబ్ఫారమ్స్ హాష్ టేబుల్
- తరువాత పేజీ వెబ్ఫారమ్స్ ఎక్స్ఎమ్ఎల్ ఫైల్
SortedList ఆబ్జెక్ట్ ArrayList మరియు Hashtable ఆబ్జెక్ట్స్ లాంటి లక్షణాలు కలిగి ఉంటుంది.
SortedList ఆబ్జెక్ట్
SortedList ఆబ్జెక్ట్ కీ/విలువ పరిధిలో ప్రాజెక్ట్స్ కలిగి ఉంటుంది. SortedList ఆబ్జెక్ట్ పదార్థాలను అక్షర క్రమం లేదా సంఖ్యాక్రమం ప్రకారం స్వయంచాలకంగా క్రమీకరిస్తుంది.
Add() మెథడ్ ద్వారా SortedList కు ఆయాములను జోడించండి. SortedList చివరి పరిమాణానికి TrimToSize() మెథడ్ ద్వారా సర్దుబాటు చేయవచ్చు.
క్రింది కోడ్ ఒక పేరు చేసిన మెయ్క్యూర్స్ సృష్టిస్తుంది మరియు నాలుగు ఎలిమెంట్స్ జోడిస్తుంది:
<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New SortedList mycountries.Add("C","China") 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:Listbox
RadioButtonList కంట్రోల్ని డేటాను జోడించడానికి, ముందుగా aspx ఫైల్లో RadioButtonList కంట్రోల్ సృష్టించండి (ఏ అస్ప్:లిస్టింగ్ ఇంజెక్షన్ కంట్రోల్స్ లేవు):
<html> <body> <form runat="server"> <asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" /> </form> </body> </html>
ఆపై కొనసాగి పోయాలి అప్రిషన్ జాబితా స్క్రిప్ట్ జోడించండి:
<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New SortedList mycountries.Add("C","China") 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("C","China") 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>
- ముందు పేజీ వెబ్ఫారమ్స్ హాష్ టేబుల్
- తరువాత పేజీ వెబ్ఫారమ్స్ ఎక్స్ఎమ్ఎల్ ఫైల్