ASP.NET - SortedList ऑब्जेक्ट

SortedList ऑब्जेक्ट ArrayList और Hashtable ऑब्जेक्ट की विशेषताओं को मिलाता है。

SortedList ऑब्जेक्ट

SortedList ऑब्जेक्ट चाबी/मूल्य प्रतियोगिता के रूप में एलीमेंट रखता है।SortedList ऑब्जेक्ट चाबी के अक्षर क्रम या संख्यात्मक क्रम में स्वचालित रूप से एलीमेंटों को क्रमबद्ध कर सकता है。

Add() मथडड़ी के द्वारा SortedList में एलीमेंट जोड़ें।SortedList TrimToSize() मथडड़ी के द्वारा अंतिम आकार को समायोजित कर सकती है。

नीचे की कोड एक नाम mycountries के SortedList बनाती है और चार एलीमेंट जोड़ती है:

<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 नियंत्रक बनाएं (कोई asp:ListItem एलीमेंट नहीं होना चाहिए):

<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>

तब हम एक सबसे जोड़ते हैं, जो सबसे रेडियो बटन लिस्ट कन्ट्रोल में पढ़ा जाने वाला है। जब रेडियो बटन को क्लिक किया जाता है तो लेबल में पाठ दिखाया जाता है: }}

<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>

इस उदाहरण को दिखाएं