ASP.NET - ArrayList 对象
- ਪਿੰਡਾ ਪੰਨਾ WebForms ਡੇਟਾ ਬਾਈੰਡਿੰਗ
- ਅਗਲਾ ਪੰਨਾ وایب فورمس ہاش تیبل
ArrayList 对象是包含单一数据值的项目的集合。
创建 ArrayList
ArrayList 对象是包含单一数据值的项目的集合。
通过 Add() 方法向 ArrayList 添加项目。
下面的代码创建了一个新的 ArrayList 对象,名为 mycountries,并添加了四个项目:
<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
ਜੇਕਰ ਤੁਸੀਂ ਡਾਟਾ ਨੂੰ RadioButtonList ਕੰਟਰੋਲ ਨਾਲ ਬਾਂਧਣਾ ਚਾਹੁੰਦੇ ਹੋ, ਤਾਂ ਪਹਿਲਾਂ ਇੱਕ .aspx ਪੇਜ਼ ਵਿੱਚ RadioButtonList ਕੰਟਰੋਲ ਬਣਾਓ (ਧਿਆਨ ਦੇਓ ਕਿ ਕੋਈ asp:ListItem ਅਣਗਿਣਤ ਨਹੀਂ ਹੈ):
<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 ਕੰਟਰੋਲ ਨੂੰ ਸਮਾਚਾਰ ਸੋਮੇ ਨਾਲ ਬੰਧ ਕਰਦਾ ਹੈ。
ਟਿੱਪਣੀਆਂ:ਡੇਟਾ ਮੁੱਲ ਨੂੰ ਕੰਟਰੋਲ ਦੇ ਟੈਕਸਟ ਅਤੇ ਮੁੱਲ ਸ਼ਰੂਆਤ ਦੇ ਰੂਪ ਵਿੱਚ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। ਟੈਕਸਟ ਤੋਂ ਵੱਖ ਮੁੱਲ ਜੋੜਨ ਲਈ, ਹਾਲਾਂਕਿ, ਹੈਂਟਾਸ਼ੇਟ ਵਸਤੂ ਜਾਂ ਸਰਟਿੰਗ ਲਿਸਟ ਵਸਤੂ ਦਾ ਉਪਯੋਗ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ。
- ਪਿੰਡਾ ਪੰਨਾ WebForms ਡੇਟਾ ਬਾਈੰਡਿੰਗ
- ਅਗਲਾ ਪੰਨਾ وایب فورمس ہاش تیبل