ASP.Net/Collections/ArrayList
Версия от 15:30, 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)
<%@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>
ArrayList: remove item by index (VB.net)
<%@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>
ArrayList: remove item (VB.net)
<%@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>
Bind arrayList to asp:dropdownlist (C#)
<%@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>
Inset element to ArrayList by index (C#)
<%@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>
Remove object from ArrayList by Index (C#)
<%@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>
Remove object from ArrayList (C#)
<%@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>
Use array and ArrayList (VB.net)
<%@ 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">
<p>
Select a color from the list:<asp:DropDownList id="ddlColorList" runat="server"></asp:DropDownList>
</p>
<p>
Then select a font sytle from the list:
<asp:DropDownList id="ddlFontList" runat="server"></asp:DropDownList>
</p>
<p>
<asp:Button id="btnSelectColor" onclick="btnSelectColor_Click" runat="server" Text="Click here!"></asp:Button>
</p>
<p>
<asp:Label id="lblOutputMessage" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
Use ArrayList to fill dropdown value (C#)
<%@ 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>