ASP.NET - SortedList ਆਬਜੈਕਟ
- ਪਿਛਲਾ ਪੰਨਾ WebForms Hashtable
- ਅਗਲਾ ਪੰਨਾ WebForms XML ਫਾਈਲ
SortedList ਆਬਜੈਕਟ ArrayList ਅਤੇ Hashtable ਆਬਜੈਕਟ ਦੀਆਂ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਰੱਖਦਾ ਹੈ。
SortedList ਆਬਜੈਕਟ
SortedList ਆਬਜੈਕਟ ਕੀ/ਮੁੱਲ ਪਾਰ ਵਿੱਚ ਆਈਟਮਾਂ ਨੂੰ ਰੱਖਦਾ ਹੈ। SortedList ਆਬਜੈਕਟ ਆਈਟਮਾਂ ਨੂੰ ਅਕਸਰ ਚਾਰਟਰ ਕਿਰਦ ਜਾਂ ਨੰਬਰ ਕਿਰਦ 'ਚ ਸਵੈਚਾਲਿਤ ਤੌਰ 'ਚ ਕਰ ਸਕਦਾ ਹੈ。
Add() ਮੱਥੌਡ ਰਾਹੀਂ SortedList ਵਿੱਚ ਆਈਟਮਾਂ ਜੋੜੋ। SortedList TrimToSize() ਮੱਥੌਡ ਰਾਹੀਂ ਅੰਤਿਮ ਕਦਰ ਤੱਕ ਸਜਾਓ ਸਕਦਾ ਹੈ。
ਹੇਠ ਦੇ ਕੋਡ 'ਚ ਇੱਕ ਨਾਮ ਵਾਲਾ SortedList ਬਣਾਇਆ ਗਿਆ ਹੈ mycountries ਅਤੇ ਚਾਰ ਤੰਤਰ ਜੋੜੇ ਗਏ ਹਨ:
<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>
- ਪਿਛਲਾ ਪੰਨਾ WebForms Hashtable
- ਅਗਲਾ ਪੰਨਾ WebForms XML ਫਾਈਲ