I'm trying the following syntax, but getting errors. Can anybody help?
for (int i = 0; i <= orders.Count ; i++)
{
sb.Append("<br/><table>");
sb.Append("<tr><td>" + orders[i]["bacon"].ToString());
}
FULL CODE :
protected void Page_Load(object sender, EventArgs e)
{
ArrayList orders = new ArrayList();
StringBuilder sb = new StringBuilder();
orders = (ArrayList)Session["Order"];
sb.Append("<form id='form1' runat='server'>");
sb.Append("<div
style='text-align:center;page-break-after:always;'>");
sb.Append("<table style='width:6.5in;border:solid 1px
black;height:9.5in'>");
sb.Append("<tr>");
sb.Append("<td valign=top>");
sb.Append("<table width=90%>");
sb.Append("<tr>");
sb.Append("<td align=left valign=middle>ORDER</td>");
for (int i = 0; i <= orders.Count ; i++)
{
sb.Append("<br/><table>");
sb.Append("<tr><td>" + orders[i]["bacon"].ToString());
}
sb.Append("</td></tr></table></td></tr></table></div></form>");
DisplayOrder.InnerHtml += sb.ToString();
}
Arne Vajhøj - 14 Oct 2007 23:13 GMT
> I'm trying the following syntax, but getting errors. Can anybody help?
>
[quoted text clipped - 34 lines]
> DisplayOrder.InnerHtml += sb.ToString();
> }
1) It will be a bit easier for us if you tell us which errors you get.
2) I am not sure appending HTML is the best way to do this in ASP.NET.
Arne
Family Tree Mike - 15 Oct 2007 01:02 GMT
your order loops are going one step too far, and should go as follows:
for (int i = 0; i < orders.count; ++i)
However, I think that the following is more understandable, in my opinion:
foreach (Sandwitch s in orders)
{
}
> > I'm trying the following syntax, but getting errors. Can anybody help?
> >
[quoted text clipped - 40 lines]
>
> Arne
John B - 15 Oct 2007 07:24 GMT
> I'm trying the following syntax, but getting errors. Can anybody help?
>
> for (int i = 0; i <= orders.Count ; i++)
> {
You will need to cast the items as the ArrayList stores objects.
Sandwich item = (Sandwich)orders[i];
...item["bacon"].ToString();
<...>
HTH
JB
Mike P - 15 Oct 2007 09:14 GMT
John,
>>Sandwich item = (Sandwich)orders[i];
>>...item["bacon"].ToString();
So what is the correct full syntax to get at the item["bacon]?
Christof Nordiek - 15 Oct 2007 12:09 GMT
> John,
>
>>>Sandwich item = (Sandwich)orders[i];
>>>...item["bacon"].ToString();
>
> So what is the correct full syntax to get at the item["bacon]?
given that bacon is a property of the Sandwich-class:
item.bacon
the codeexample of JB presumes, that Sandwich has an indexer with parameter
of string and you want to return the item called bacon.
In that case item["bacon"] is allready the right syntax.
Christof
>I have an arraylist that is made up of Sandwich objects, which have
> properties for each ingredient. What is the correct syntax to loop
> through the arraylist and get at each of these properties for each item
> in the array?
Unless you are bound to Framework 1.1 for some reason you should use
List<Sandwich> instead of ArrayList.
Christof