Hi,
I have trouble getting the right items out of a datalist. The thing is that I have a shopping basket with several product lines, and I want to store each line separately in a database to create order history for each customer. I have a loop, which is looping through the datalist storing data in the database, but here it suddenly stopped. I want to send in an integer which represent the line number, and then retreive right items for this line.
CONFIRM.ASPX.CS
for (int i=0; i<ShoppingCartList.Items.Count; i++)
{
string strSQL1 = "INSERT INTO OrdProducts (OrderId, Qty, Product) VALUES (?, ?, ?)";
OleDbCommand myCmd1 = new OleDbCommand(strSQL1, myConn );
Market.OrderList shoppingCart = ((Market.OrderList) Session["ShoppingCart"]);
myCmd1.Parameters.Add("@OrderId", System.Data.OleDb.OleDbType.VarChar,100).Value = txtNewOrderNo.Text;
HtmlInputText qty = (HtmlInputText) ShoppingCartList.Items.FindControl("Qty");
myCmd1.Parameters.Add("@Qty", System.Data.OleDb.OleDbType.VarChar,100).Value = qty.Value;
string GetProductName = shoppingCart.ProductName(i);
myCmd1.Parameters.Add("@Product", System.Data.OleDb.OleDbType.VarChar,1000).Value = GetProductName;
myCmd1.ExecuteNonQuery();
}
CONFIRM.ASPX
<!-- The datalist -->
<ItemTemplate>
<tr class="h2">
<td width="35">
<input type=text size=1 id="Qty" runat=server value='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' NAME="Qty">
</td>
<td width="350">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</td></tr></ItemTemplate>
MARKET.CS
public string ProductName(int i)
{
string ProductName = "";
IEnumerator items = orders.Values.GetEnumerator();
while(items.MoveNext())
{
ProductName = ((OrderItem) items.Current).name;
}
return ProductName;
}
The problem seems to be in the market.cs file. I only found a way to read from the datalist through a IEnumerator, but the problem with this is, as you see, that it loops to the last product line and only returns the items from the last line! Con someone please give me some help with this one! Will be very greatful!!! Thanks in advance!!!
I have trouble getting the right items out of a datalist. The thing is that I have a shopping basket with several product lines, and I want to store each line separately in a database to create order history for each customer. I have a loop, which is looping through the datalist storing data in the database, but here it suddenly stopped. I want to send in an integer which represent the line number, and then retreive right items for this line.
CONFIRM.ASPX.CS
for (int i=0; i<ShoppingCartList.Items.Count; i++)
{
string strSQL1 = "INSERT INTO OrdProducts (OrderId, Qty, Product) VALUES (?, ?, ?)";
OleDbCommand myCmd1 = new OleDbCommand(strSQL1, myConn );
Market.OrderList shoppingCart = ((Market.OrderList) Session["ShoppingCart"]);
myCmd1.Parameters.Add("@OrderId", System.Data.OleDb.OleDbType.VarChar,100).Value = txtNewOrderNo.Text;
HtmlInputText qty = (HtmlInputText) ShoppingCartList.Items.FindControl("Qty");
myCmd1.Parameters.Add("@Qty", System.Data.OleDb.OleDbType.VarChar,100).Value = qty.Value;
string GetProductName = shoppingCart.ProductName(i);
myCmd1.Parameters.Add("@Product", System.Data.OleDb.OleDbType.VarChar,1000).Value = GetProductName;
myCmd1.ExecuteNonQuery();
}
CONFIRM.ASPX
<!-- The datalist -->
<ItemTemplate>
<tr class="h2">
<td width="35">
<input type=text size=1 id="Qty" runat=server value='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' NAME="Qty">
</td>
<td width="350">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</td></tr></ItemTemplate>
MARKET.CS
public string ProductName(int i)
{
string ProductName = "";
IEnumerator items = orders.Values.GetEnumerator();
while(items.MoveNext())
{
ProductName = ((OrderItem) items.Current).name;
}
return ProductName;
}
The problem seems to be in the market.cs file. I only found a way to read from the datalist through a IEnumerator, but the problem with this is, as you see, that it loops to the last product line and only returns the items from the last line! Con someone please give me some help with this one! Will be very greatful!!! Thanks in advance!!!