Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 8th, 2006, 10:09 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTMLTable

I am trying to display a collection in a table (with header cells for each column), but the table only pumps out one element of the collection and then creates one empty row for each element in the collection. Any ideas on how to fix this?

Thanks.

Reply With Quote
  #2 (permalink)  
Old March 8th, 2006, 10:23 PM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you post the error ridden HTML source and the HTML generating function?

It sounds like you aren't advancing through your DataSet or RecordSet.

- A.Kahtava
Reply With Quote
  #3 (permalink)  
Old March 9th, 2006, 01:23 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is what i have for my code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrazyEddie; //my own namespace for vehicles

public partial class Listing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        long totalwhole = 0;
        long totalretail = 0;
        ArrayList selection = new ArrayList();
        selection=(ArrayList)Session["Vehicles"];
        TableRow TOProw = new TableRow();
        TableCell VINcell = new TableCell();
        VINcell.Text = "VIN";
        TOProw.Cells.Add(VINcell);
        TableCell MANUFACTURERcell = new TableCell();
        MANUFACTURERcell.Text = "MANUFACTURER";
        TOProw.Cells.Add(MANUFACTURERcell);
        TableCell MAKEcell = new TableCell();
        MAKEcell.Text = "MAKE";
        TOProw.Cells.Add(MAKEcell);
        TableCell MODELcell = new TableCell();
        MODELcell.Text = "MODEL";
        TOProw.Cells.Add(MODELcell);
        TableCell YEARcell = new TableCell();
        YEARcell.Text = "YEAR";
        TOProw.Cells.Add(YEARcell);
        TableCell MANUDATEcell = new TableCell();
        MANUDATEcell.Text = "MANUDATE";
        TOProw.Cells.Add(MANUDATEcell);
        TableCell SHOWDATEcell = new TableCell();
        SHOWDATEcell.Text = "SHOWDATE";
        TOProw.Cells.Add(SHOWDATEcell);
        TableCell VCOLORcell = new TableCell();
        VCOLORcell.Text = "VCOLOR";
        TOProw.Cells.Add(VCOLORcell);
        TableCell GVWcell = new TableCell();
        GVWcell.Text = "GVW";
        TOProw.Cells.Add(GVWcell);
        TableCell ESIZEcell = new TableCell();
        ESIZEcell.Text = "ESIZE";
        TOProw.Cells.Add(ESIZEcell);
        TableCell MSRPcell = new TableCell();
        MSRPcell.Text = "MSRP";
        TOProw.Cells.Add(MSRPcell);
        TableCell WHOLEcell = new TableCell();
        WHOLEcell.Text = "WHOLESALE";
        TOProw.Cells.Add(WHOLEcell);
        TableCell SALEcell = new TableCell();
        SALEcell.Text = "SALES DATE";
        TOProw.Cells.Add(SALEcell);
        TableCell OTHERcell = new TableCell();
        OTHERcell.Controls.Add(new LiteralControl("OTHER"));
        TOProw.Cells.Add(OTHERcell);
        CarTable.Rows.Add(TOProw);
        if (selection != null)
        {
            foreach (Vehicle v in selection)
            //foreach (Vehicle v in selection)
            {
                string s = null;
                TableRow TBLrow = new TableRow();
                TableCell inVINcell = new TableCell();
                VINcell.Text = v.getVIN();
                TBLrow.Cells.Add(inVINcell);
                TableCell inMANUFACTURERcell = new TableCell();
                MANUFACTURERcell.Text = v.getManufacturer();
                TBLrow.Cells.Add(inMANUFACTURERcell);
                TableCell inMAKEcell = new TableCell();
                MAKEcell.Text = v.getMake();
                TBLrow.Cells.Add(inMAKEcell);
                TableCell inMODELcell = new TableCell();
                MODELcell.Text = v.getModel();
                TBLrow.Cells.Add(inMODELcell);
                TableCell inYEARcell = new TableCell();
                YEARcell.Text = v.getYear();
                TBLrow.Cells.Add(inYEARcell);
                TableCell inMANUDATEcell = new TableCell();
                MANUDATEcell.Text = v.getManuDate().ToString();
                TBLrow.Cells.Add(inMANUDATEcell);
                TableCell inSHOWDATEcell = new TableCell();
                SHOWDATEcell.Text = v.getShowDate().ToString();
                TBLrow.Cells.Add(inSHOWDATEcell);
                TableCell inVCOLORcell = new TableCell();
                VCOLORcell.Text = v.getVColor();
                TBLrow.Cells.Add(inVCOLORcell);
                TableCell inGVWcell = new TableCell();
                GVWcell.Text = v.getGVW() + "LB.";
                TBLrow.Cells.Add(inGVWcell);
                TableCell inESIZEcell = new TableCell();
                ESIZEcell.Text = v.getEngineSize().ToString() + "L.";
                TBLrow.Cells.Add(inESIZEcell);
                TableCell inMSRPcell = new TableCell();
                MSRPcell.Text = v.getMSRP().ToString();
                TBLrow.Cells.Add(inMSRPcell);
                TableCell inWHOLEcell = new TableCell();
                WHOLEcell.Text = v.getWholesalePrice().ToString();
                TBLrow.Cells.Add(inWHOLEcell);
                TableCell inSALEcell = new TableCell();
                SALEcell.Text = v.getSDate().ToString();
                TBLrow.Cells.Add(inSALEcell);
                TableCell inOTHERcell = new TableCell();
                if (v.getisAir())
                {
                    Aircraft w = (Aircraft)v;
                    s = "Aircraft" + '\n' +
                        "Number of passengers: " + w.getPassNum().ToString() + '\n' +
                        "Wingspan: "+ w.getWingspan().ToString() + "ft.";
                }
                else if (v.getisAuto())
                {
                    Automobile a = (Automobile)v;
                    s = "Automobile" + '\n' +
                        "Number of pasengers: " + a.getPassNum();
                }
                else if (v.getisMCycle())
                {
                    Motorcycle b = (Motorcycle)v;
                    s = "Motorcycle";
                }
                else if (v.getisTruck())
                {
                    Truck c = (Truck)v;
                    s = "Truck" + '\n' +
                        "Number of passengers: " + c.getPassNum().ToString() + '\n' +
                        "Number of axles: " + c.getAxleNum().ToString() + '\n' +
                        "Gross Vehicle Weight Rating: " + c.getGVWR();
                }
                else if (v.getisWatercraft())
                {
                    Watercraft d = (Watercraft)v;
                    s = "Watercraft" + '\n' +
                        "Number of passengers: " + d.getPassNum().ToString() + '\n' +
                        "Length: " + d.getLength().ToString() + "ft.";
                }
                else
                {
                    s = "I dunno\n";
                }
                OTHERcell.Text = s;
                TBLrow.Cells.Add(inOTHERcell);
                CarTable.Rows.Add(TBLrow);
                totalwhole += v.getWholesalePrice();
                totalretail += v.getMSRP();
            }
            TableRow TOTWHOLErow = new TableRow();
            TableCell TWLcell = new TableCell();
            TWLcell.Text = "TOTAL WHOLESALE VALUE: $";
            TableCell TWcell = new TableCell();
            TWcell.Text = totalwhole.ToString();
            TOTWHOLErow.Cells.Add(TWLcell);
            TOTWHOLErow.Cells.Add(TWcell);
            TableRow TOTRETAILrow = new TableRow();
            TableCell TRLcell = new TableCell();
            TRLcell.Text = "TOTAL RETAIL VALUE: $";
            TableCell TRcell = new TableCell();
            TRcell.Text = totalretail.ToString();
            TOTRETAILrow.Cells.Add(TRLcell);
            TOTRETAILrow.Cells.Add(TRcell);
            CarTable.Rows.Add(TOTWHOLErow);
            CarTable.Rows.Add(TOTRETAILrow);
        }
        else
        {
            TableRow tr = new TableRow();
            TableCell tc = new TableCell();
            tc.Text = "No vehicles!";
            tr.Cells.Add(tc);
            CarTable.Rows.Add(tr);
        }
    }
}

Reply With Quote
  #4 (permalink)  
Old March 9th, 2006, 07:34 PM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you post the error ridden HTML source code?

- A.Kahtava
Reply With Quote
  #5 (permalink)  
Old March 9th, 2006, 09:51 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no error, it just places all the text into one row of a html and creates a blank number of rows equal to the amount in the collection.

Reply With Quote
  #6 (permalink)  
Old March 9th, 2006, 10:45 PM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It would be beneficial to see the HTML source.
Debugging should be performed systematically.

I think Steve McConnell put it best:

The Scientific way of debugging
1. Gather data through repeatable experiments.
2. Form a hypothesis that accounts to relevant data.
3. Design and experiment to prove the hypothesis.
4. Prove or disprove the hypothesis.
5. Repeat as needed.

Without step 1 (in our case viewing the generated HTML source) we can't draw a hypothesis.
I can take your explanation from the previous post, but the English language is often vague.
Sometimes seeing the resulting code is simpler than a description.

- A.Kahtava
Reply With Quote
  #7 (permalink)  
Old March 9th, 2006, 11:41 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have done experimentation all day on this project and here is what is continually pumped out in the html:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
    Listing of Vehicles
</title></head>
<body>
    <form name="form1" method="post" action="Listing.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU1NzIwMjU5NWRklBTytuMZVvTHkTEfMOxm9QhmX1Y =" />
</div>

    <br />

    <br />
    <br />
    <br />
    <br />
    <br />
    <div>
        <table id="CarTable" cellpadding="3">
    <tr>
        <td>VINdoi</td>

        <td>MANUFACTURERhfoew</td>
        <td>MAKEhdoew</td>
        <td>MODELhdoew</td>
        <td>YEAR10</td>
        <td>MANUDATE10/10/0010 12:00:00 AM</td>
        <td>SHOWDATE10/10/0010 12:00:00 AM</td>

        <td>VCOLOR101</td>
        <td>GVWhfoewLB.</td>
        <td>ESIZE10L.</td>
        <td>MSRP10</td>
        <td>WHOLESALE10</td>
        <td>SALES DATE10/10/0010 12:00:00 AM</td>

        <td>OTHERMotorcycle</td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>

        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>

    </tr>
    <tr>
        <td>TOTAL WHOLESALE VALUE: $</td>
        <td>10</td>
    </tr>
    <tr>
        <td>TOTAL RETAIL VALUE: $</td>

        <td>10</td>
    </tr>
</table>

        <span id="Title" style="color:Red;font-family:Arial Black;font-size:X-Large;z-index: 101; left: 501px; position: absolute; top: 15px">Listing of All Vehicles</span>
        <div id="TitleBorder" style="background-color:Blue;border-color:Blue;height:6px;width:1253px;z-index: 102; left: 14px; position: absolute; top: 49px">


</div>
        <input type="submit" name="ReturnBtn" value="Return To Entry" id="ReturnBtn" style="z-index: 103;
            left: 62px; position: absolute; top: 104px" />
        &nbsp;


    </div>

<div>

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKktYXmBAL/jtaQDaDiPUsHfZ3FAb1kZcU/rN87aZ0t" />
</div></form>
</body>
</html>


Reply With Quote
  #8 (permalink)  
Old March 10th, 2006, 12:44 AM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

foreach (Vehicle v in selection){
    string s = null;
    TableRow TBLrow = new TableRow();
    TableCell inVINcell = new TableCell();
    VINcell.Text = v.getVIN();
    TBLrow.Cells.Add(inVINcell);

in the above case VINcell should be inVINcell, this error is consistent through all the code in your foreach loop.

- A.Kahtava
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which one is much faster in gridview, htmltable anshumannidhi BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 October 11th, 2006 03:50 AM



All times are GMT -4. The time now is 08:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.