Groups | Blog | Home
all groups > asp.net webcontrols > february 2005 >

asp.net webcontrols : How to Add / Remove From Collection


Chuck Insight
2/27/2005 3:46:49 PM
Please Help a Novice with a WEB Form Problem.

I have discovered that both an Array and an ArrayList can contain a
collection of 300 integers. The things I cannot seem to figure out are:
1 - How to populate these objects,
2 - How to test the members to determine whether they contain a particular
value,
3 - How to delete or set to zero the member after it passes the test, and
4 - How to populate a different Array(List) with the value of the original
list.


I have also discovered a few methods within these classes such as .Equals
..Add .Remove .GetValue, which seem to hold significant parts of my answer;
but the book I have falls very short of explaining how to make them work the
way she indicates.

I would greatly appreciate any help (or a link to a tutor that shows
examples) that clearly explains how to deploy these methods.

Thanks very much,
Chuck

Chuck Insight
2/27/2005 4:06:36 PM
Please Help a Novice with a WEB Form Problem (Coded in VB - Sorry, I forgot
to mention that in my initial post.)

I have discovered that both an Array and an ArrayList can contain a
collection of 300 integers. The things I cannot seem to figure out are:
1 - How to populate these objects,
2 - How to test the members to determine whether they contain a particular
value,
3 - How to delete or set to zero the member after it passes the test, and
4 - How to populate a different Array(List) with the value of the original
list.


I have also discovered a few methods within these classes such as .Equals
..Add .Remove .GetValue, which seem to hold significant parts of my answer;
but the book I have falls very short of explaining how to make them work the
way she indicates.

I would greatly appreciate any help (or a link to a tutor that shows
examples) that clearly explains how to deploy these methods.

Thanks very much,
Chuck

Ken Cox [Microsoft MVP]
2/28/2005 5:58:12 PM
There are quite a few samples on using arraylist. You might want to
investigate here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclassaddtopic.asp

BTW, what is the book and name of the author? The author should know that
the information was insufficient.

[quoted text, click to view]
Ken Cox [Microsoft MVP]
2/28/2005 11:07:48 PM
Hey Chuck,

It looks like you're taking too many shortcuts. Here's some code that works
for me. Does it work for you?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="vb" AutoEventWireup="true" %>
<%@ Import namespace="System.Collections" %>
<%@ Import namespace="Microsoft.VisualBasic" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>arraylstscript</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script runat='server' language="vb">
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs)

dim Samples as New ArrayList()
Samples.Add("1")
Samples.Add("2")
Samples.Add("3")
Samples.Add("4")
Samples.Add("5")
Samples.Add("6")
Samples.Add("7")
Samples.Add("8")
Samples.Add("9")
Samples.Add("10")
Samples.Add("11")
Samples.Add("12")
Samples.Add("13")
Samples.Add("14")
Samples.Add("15")
Samples.Add("16")
Samples.Add("17")
Samples.Add("18")
Samples.Add("19")
Samples.Add("20")
Samples.Add("21")
Samples.Add("22")
Samples.Add("23")
Samples.Add("24")
Samples.Add("25")
Samples.Add("26")
Samples.Add("27")
Samples.Add("28")
Samples.Add("29")
Samples.Add("30")

DropDownList1.DataSource = Samples
DropDownList1.DataBind()
end sub

</script>
</head>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:dropdownlist id="DropDownList1"
runat="server"></asp:dropdownlist>
</form>
</body>
</html>
Chuck Insight
3/1/2005 1:30:24 AM
Thanks for the hint Ken, but I have already been there and seen that.
Perhaps knowing the code for S.ASPX might help:

<html><head></head><body>
<Script runat=3D'server'>
Dim Samples as New ArrayList()
Samples.Add("1")
Samples.Add("2")
Samples.Add("3")
Samples.Add("4")
Samples.Add("5")
Samples.Add("6")
Samples.Add("7")
Samples.Add("8")
Samples.Add("9")
Samples.Add("10")
Samples.Add("11")
Samples.Add("12")
Samples.Add("13")
Samples.Add("14")
Samples.Add("15")
Samples.Add("16")
Samples.Add("17")
Samples.Add("18")
Samples.Add("19")
Samples.Add("20")
Samples.Add("21")
Samples.Add("22")
Samples.Add("23")
Samples.Add("24")
Samples.Add("25")
Samples.Add("26")
Samples.Add("27")
Samples.Add("28")
Samples.Add("29")
Samples.Add("30")</Script></body></html>

The error returned by the browser is:
c:\inetpub\wwwroot\s.aspx(20) : error BC30188: Declaration expected.
Samples.Add("1")

What in the world am I doing wrong?



[quoted text, click to view]
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/cpref/=
html/frlrfsystemcollectionsarraylistclassaddtopic.asp
[quoted text, click to view]
Chuck Insight
3/1/2005 11:33:17 AM
Thanks a 1,000,000 Ken.
You have officially become my hero.
Now that I have the hard part in place, I will try to finish the balance of
my project.


[quoted text, click to view]

AddThis Social Bookmark Button