ASP.Net/Collections/ArrayList — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:51, 26 мая 2010
Содержание
- 1 ArrayList: insert value by index (VB.net)
- 2 ArrayList: remove item by index (VB.net)
- 3 ArrayList: remove item (VB.net)
- 4 Bind arrayList to asp:dropdownlist (C#)
- 5 Inset element to ArrayList by index (C#)
- 6 Remove object from ArrayList by Index (C#)
- 7 Remove object from ArrayList (C#)
- 8 Use array and ArrayList (VB.net)
- 9 Use ArrayList to fill dropdown value (C#)
ArrayList: insert value by index (VB.net)
<source lang="csharp">
<%@Page language="vb" %> <script runat="server" language="vb"> Sub Page_Load()
Dim AnimalArrayList as new ArrayList() AnimalArrayList.Add("Dog") AnimalArrayList.Add("Cat") AnimalArrayList.Add("Elephant") AnimalArrayList.Add("Lion") AnimalArrayList.Add("Cat") AnimalArrayList.Insert(2,"Platypus") MyDropDownList.DataSource = AnimalArrayList MyDropDownList.DataBind()
End Sub </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
ArrayList: remove item by index (VB.net)
<source lang="csharp">
<%@Page language="vb" %> <script runat="server" language="vb"> Sub Page_Load()
Dim AnimalArrayList as new ArrayList AnimalArrayList.Add("Dog") AnimalArrayList.Add("Cat") AnimalArrayList.Add("Elephant") AnimalArrayList.Add("Lion") AnimalArrayList.Add("Cat") AnimalArrayList.Add("Platypus") AnimalArrayList.Insert(1,"Chicken") AnimalArrayList.Remove("Cat") AnimalArrayList.RemoveAt(0) MyDropDownList.DataSource = AnimalArrayList MyDropDownList.DataBind()
End Sub </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
ArrayList: remove item (VB.net)
<source lang="csharp">
<%@Page language="vb" %> <script runat="server" language="vb"> Sub Page_Load()
Dim AnimalArrayList as new ArrayList AnimalArrayList.Add("Dog") AnimalArrayList.Add("Cat") AnimalArrayList.Add("Elephant") AnimalArrayList.Add("Lion") AnimalArrayList.Add("Cat") AnimalArrayList.Add("Platypus") AnimalArrayList.Insert(1,"Chicken") AnimalArrayList.Remove("Cat") AnimalArrayList.RemoveAt(0) MyDropDownList.DataSource = AnimalArrayList MyDropDownList.DataBind()
End Sub </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
Bind arrayList to asp:dropdownlist (C#)
<source lang="csharp">
<%@Page Language="c#" %> <script runat="server" Language="c#">
void Page_Load() { ArrayList AnimalArrayList = new ArrayList(); AnimalArrayList.Add("Dog"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Elephant"); AnimalArrayList.Add("Lion"); AnimalArrayList.Add("Cat"); MyDropDownList.DataSource = AnimalArrayList; MyDropDownList.DataBind();
} </script> <html> <form id="Form1" method="post" runat="server">
<asp:dropdownlist id="MyDropDownList" runat="server" />
</form> </html>
</source>
Inset element to ArrayList by index (C#)
<source lang="csharp">
<%@Page Language="c#" %> <script runat="server" Language="c#">
void Page_Load() { ArrayList AnimalArrayList = new ArrayList(); AnimalArrayList.Add("Dog"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Elephant"); AnimalArrayList.Add("Lion"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Platypus"); AnimalArrayList.Insert(1,"Chicken"); AnimalArrayList.Remove("Cat"); AnimalArrayList.RemoveAt(0); MyDropDownList.DataSource = AnimalArrayList; MyDropDownList.DataBind();
} </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
Remove object from ArrayList by Index (C#)
<source lang="csharp">
<%@Page Language="c#" %> <script runat="server" Language="c#">
void Page_Load() { ArrayList AnimalArrayList = new ArrayList(); AnimalArrayList.Add("Dog"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Elephant"); AnimalArrayList.Add("Lion"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Platypus"); AnimalArrayList.Insert(1,"Chicken"); AnimalArrayList.Remove("Cat"); AnimalArrayList.RemoveAt(0); MyDropDownList.DataSource = AnimalArrayList; MyDropDownList.DataBind();
} </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
Remove object from ArrayList (C#)
<source lang="csharp">
<%@Page Language="c#" %> <script runat="server" Language="c#">
void Page_Load() { ArrayList AnimalArrayList = new ArrayList(); AnimalArrayList.Add("Dog"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Elephant"); AnimalArrayList.Add("Lion"); AnimalArrayList.Add("Cat"); AnimalArrayList.Add("Platypus"); AnimalArrayList.Insert(1,"Chicken"); AnimalArrayList.Remove("Cat"); AnimalArrayList.RemoveAt(0); MyDropDownList.DataSource = AnimalArrayList; MyDropDownList.DataBind();
} </script> <html> <form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server" /> </form> </html>
</source>
Use array and ArrayList (VB.net)
<source lang="csharp">
<%@ Page Language="VB" %> <script runat="server">
Dim ColorList(6) as String Dim FontList as new ArrayList() Sub Page_Load " Add the colors to the array ColorList(0) = "Red" ColorList(1) = "Orange" ColorList(2) = "Yellow" ColorList(3) = "Green" ColorList(4) = "Blue" ColorList(5) = "Indigo" ColorList(6) = "Violet" FontList.Add("Times New Roman") FontList.Add("Arial") FontList.Add("Verdana") FontList.Add("Comic Sans MS") If Not Page.IsPostback Dim ColorName as String For Each ColorName in ColorList ddlColorList.Items.Add(ColorName) Next ddlFontList.DataSource = FontList ddlFontList.DataBind() End If End Sub Sub btnSelectColor_Click(sender As Object, e As EventArgs) lblOutputMessage.Text = "You selected " & _ ddlColorList.SelectedItem.Value & " text written in " & _ ddlFontList.SelectedItem.Value lblOutputMessage.ForeColor = _ System.Drawing.Color.FromName(ddlColorList.SelectedItem.Text) lblOutputMessage.Font.Name = _ ddlFontList.SelectedItem.Text End Sub
</script> <html> <head> </head> <body>
<form runat="server">
Select a color from the list:<asp:DropDownList id="ddlColorList" runat="server"></asp:DropDownList>
Then select a font sytle from the list: <asp:DropDownList id="ddlFontList" runat="server"></asp:DropDownList>
<asp:Button id="btnSelectColor" onclick="btnSelectColor_Click" runat="server" Text="Click here!"></asp:Button>
<asp:Label id="lblOutputMessage" runat="server"></asp:Label>
</form>
</body> </html>
</source>
Use ArrayList to fill dropdown value (C#)
<source lang="csharp">
<%@ Page Language="C#" Debug="true" %> <script runat="server">
void Page_Load() { ArrayList list = new ArrayList(); list.Add("none"); list.Add("Canada Post"); list.Add("UPS"); list.Insert(1,"FedEx"); MyDropDownList.DataSource = list; MyDropDownList.DataBind(); }
</script> <html> <head>
<title>ArrayList Example</title>
</head> <body>
<form id="Form1" method="post" runat="server"> <asp:dropdownlist id="MyDropDownList" runat="server"></asp:dropdownlist> </form>
</body> </html>
</source>