Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Display an Array List in page


Message #1 by "Ben Densmore" <ben_densmore@e...> on Mon, 2 Dec 2002 11:10:45 -0500
I'm a bit confused about displaying data from an ArrayList in a web
page. I'm just playing around with something but then it made me
curious.

 If I create a new ArrayList with about 10 items in it. Then loop
through the list I can output the list using Response.Write but let's
say I want to display that in a table in an aspx page, what would I use
to do that? Can you do a loop in the table itself?  Here is what I'm
playing with:

 

<%@ Page Language="C#" %>

<%@ import Namespace="System" %>

<%@ import Namespace="System.IO" %>

<%@ import Namespace="System.Collections" %>

<script runat="server">

 

    public void page_load(Object sender, EventArgs e) {

    

    ArrayList manufacturers = new ArrayList();

    

        manufacturers.Add("Abit");

        manufacturers.Add("Acer");

        manufacturers.Add("Acorp");

        manufacturers.Add("Ampro");

        manufacturers.Add("Amptron");

        manufacturers.Add("Aopen");

        manufacturers.Add("Asus");

        manufacturers.Add("Atrend");

        manufacturers.Add("BCM");

        manufacturers.Add("Biostar");

    

    ArrayList manufacturersUrl = new ArrayList();

    

        manufacturersUrl.Add("http://www.abit.com");

        manufacturersUrl.Add("http://www.Acer.com");

        manufacturersUrl.Add("http://www.Acorp.com");

        manufacturersUrl.Add("http://Ampro.com");

        manufacturersUrl.Add("http://www.Amptron.com");

        manufacturersUrl.Add("http://www.Aopen.com");

        manufacturersUrl.Add("http://www.Asus.com");

        manufacturersUrl.Add("http://www.Atrend.com");

        manufacturersUrl.Add("http://www.BCM.com");

        manufacturersUrl.Add("http://www.Biostar.com");

    

              foreach (string manufacturerName in manufacturers){

                manufacturer.Text = manufacturerName;

                        }

                        

                        foreach (string manufacturerUrl in
manufacturersUrl){

                         url.Text = manufacturerUrl;

                         }

     }

 

</script>

<html>

<head>

</head>

<body>

    <form runat="server">

                <table>

                    <tbody>

                        <tr>

                            <th>

                               Manufacturer Name:</th>

                            <th>

                                Manufacturers Url:</th>

                        </tr>

                    

                        <tr>

                            <td>

                               </td>

                          

                            <td>

                           <asp:label ID="url"
runat="server"></asp:label>

 
</td>

                        </tr>

                    </tbody>

                </table>

    </form>

   </body>

  </html>

 

Now I know I can't use the <asp:label> to do this, I was just
experimenting. Any help would be appreciated.

 

Thanks,

Ben

 

 


Message #2 by "Ben Densmore" <ben_densmore@e...> on Mon, 2 Dec 2002 11:35:17 -0500
Nevermind I found what I was looking for.

Thanks,
Ben

-----Original Message-----
From: Ben Densmore [mailto:ben_densmore@e...] 
Sent: Monday, December 02, 2002 11:11 AM
To: aspx_beginners
Subject: [aspx_beginners] Display an Array List in page

I'm a bit confused about displaying data from an ArrayList in a web
page. I'm just playing around with something but then it made me
curious.

 If I create a new ArrayList with about 10 items in it. Then loop
through the list I can output the list using Response.Write but let's
say I want to display that in a table in an aspx page, what would I use
to do that? Can you do a loop in the table itself?  Here is what I'm
playing with:

 

<%@ Page Language="C#" %>

<%@ import Namespace="System" %>

<%@ import Namespace="System.IO" %>

<%@ import Namespace="System.Collections" %>

<script runat="server">

 

    public void page_load(Object sender, EventArgs e) {

    

    ArrayList manufacturers = new ArrayList();

    

        manufacturers.Add("Abit");

        manufacturers.Add("Acer");

        manufacturers.Add("Acorp");

        manufacturers.Add("Ampro");

        manufacturers.Add("Amptron");

        manufacturers.Add("Aopen");

        manufacturers.Add("Asus");

        manufacturers.Add("Atrend");

        manufacturers.Add("BCM");

        manufacturers.Add("Biostar");

    

    ArrayList manufacturersUrl = new ArrayList();

    

        manufacturersUrl.Add("http://www.abit.com");

        manufacturersUrl.Add("http://www.Acer.com");

        manufacturersUrl.Add("http://www.Acorp.com");

        manufacturersUrl.Add("http://Ampro.com");

        manufacturersUrl.Add("http://www.Amptron.com");

        manufacturersUrl.Add("http://www.Aopen.com");

        manufacturersUrl.Add("http://www.Asus.com");

        manufacturersUrl.Add("http://www.Atrend.com");

        manufacturersUrl.Add("http://www.BCM.com");

        manufacturersUrl.Add("http://www.Biostar.com");

    

              foreach (string manufacturerName in manufacturers){

                manufacturer.Text = manufacturerName;

                        }

                        

                        foreach (string manufacturerUrl in
manufacturersUrl){

                         url.Text = manufacturerUrl;

                         }

     }

 

</script>

<html>

<head>

</head>

<body>

    <form runat="server">

                <table>

                    <tbody>

                        <tr>

                            <th>

                               Manufacturer Name:</th>

                            <th>

                                Manufacturers Url:</th>

                        </tr>

                    

                        <tr>

                            <td>

                               </td>

                          

                            <td>

                           <asp:label ID="url"
runat="server"></asp:label>

 
</td>

                        </tr>

                    </tbody>

                </table>

    </form>

   </body>

  </html>

 

Now I know I can't use the <asp:label> to do this, I was just
experimenting. Any help would be appreciated.

 

Thanks,

Ben

 

 






  Return to Index