 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
 | This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

October 7th, 2009, 01:21 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
list item is not being updated in the webshop
Hello Sir,
I have come through a problem while testing the webshop project. When ever I go to Edit the quantity of any product selected then its quantity and subtotal field becomes 0(zero). And on again clicking the "Edit" button it pops up the following error
Code:
Server Error in '/' Application.
'lstQuantity' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'lstQuantity' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
I have checked through the code manually, there are items in the list
as follow
Code:
<EditItemTemplate>
<asp:DropDownList ID="lstQuantity" runat="server" SelectedValue='<%# Eval("Quantity") %>'
AutoPostBack="True" OnSelectedIndexChanged="lstQuantity_SelectedIndexChanged">
<asp:ListItem Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
please tell me where I'm missing things and how to fix it....
|
|

October 7th, 2009, 01:39 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Difficult to say as you're not posting code and you're not using the original code.
All I know for sure is that indded 0 is not an item in the list so the error makes sense to me.....
|
|

October 7th, 2009, 01:55 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
list item
I have used the same indexing as in VB.Net code and code is as follows.
I'm pasting the whole code for "ShoppingCartView.ascx.cs" page. namespaces are added in page.
Code:
public partial class controls_ShoppingCartView : System.Web.UI.UserControl
{
private bool _isReadOnly = false;
decimal priceTotal = 0;
int quantityTotal = 0;
public event EventHandler CartUpdated;
/// <summary>
/// Fires when a row in the GridView is updated. Triggers an event that can be handled by a page containing this User Control.
/// </summary>
protected void GridView1_RowUpdated(object sender, System.Web.UI.WebControls.GridViewUpdatedEventArgs e)
{
if (CartUpdated != null) {
CartUpdated(sender, new System.EventArgs());
}
}
/// <summary>
/// Fires when a row in the GridView is deleted. Triggers an event that can be handled by a page containing this User Control.
/// </summary>
protected void GridView1_RowDeleted(object sender, System.Web.UI.WebControls.GridViewDeletedEventArgs e)
{
if (CartUpdated != null) {
CartUpdated(sender, new System.EventArgs());
}
}
public bool ReadOnly {
get { return _isReadOnly; }
set { _isReadOnly = value; }
}
protected void Page_Load(object sender, System.EventArgs e)
{
if (_isReadOnly) {
GridView1.Columns[5].Visible = false;
GridView1.Columns[6].Visible = false;
}
}
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
switch (e.Row.RowType) {
case DataControlRowType.DataRow:
// For each item in the datasource, get the quantity and subtotal, and store them in
// private variables called priceTotal and quantityTotal. When the Footer is databound,
// these totals are added to the Footer.
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "SubTotal"));
quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Quantity"));
break;
case DataControlRowType.Footer:
e.Row.Cells[0].Text = "Total:";
// Display the item sub total and order total in the footer
e.Row.Cells[2].Text = quantityTotal.ToString();
e.Row.Cells[4].Text = priceTotal.ToString("c");
e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;
break;
}
}
protected void lstQuantity_SelectedIndexChanged(object sender, System.EventArgs e)
{
GridView1.UpdateRow(GridView1.EditIndex, false);
GridView1.EditIndex = -1;
}
protected void odsShoppingCart_Updating(object sender, System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e)
{
// Get the Id and the new quantity from the form and assign them to the InputParams for the Update method.
// The two params will be passed to the updated method in the UpdateProductInCart method of the ShopManager.
e.InputParameters["Id"] = new Guid(GridView1.DataKeys[GridView1.EditIndex].Value.ToString());
e.InputParameters["newQuantity"] = Convert.ToInt32(((DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("lstQuantity")).SelectedValue);
}
}
|
|

October 7th, 2009, 02:01 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I don't see the problem with this snippet so I can't help. Sorry.
You'll need to debug and find out why it gets zero...
Imar
|
|

October 7th, 2009, 02:07 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
list item
OK, but tell me one thing that is there need to increase the index by 1 in every e.Rows.Cells[] method.
and what should be done with the GridView1.EditIndex = -1;
|
|

October 7th, 2009, 02:18 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I don't understand your first question.
-1 is necessary to take the GridView out of edit mode....
|
|

October 7th, 2009, 02:25 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
list item
OK, please tell me that How I can change the currency symbol i.e. from $ to something else.
|
|

October 7th, 2009, 03:01 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Please tell me this, pleaese tell me that, please tell me so.... 7 topics in a thread, no feedback on progress a nd so on.,
This is explained in the book. Also, a two second Google search could answer this.
Don't expect too much from me. There's a lot of stuff you could find our self if you'd read a bit on Google, bought some books and did some self study. I find our conversation / your threads a bit too tiring to be fun, so don't expect a lot of replies from me....
Sorry....
Imar
|
|
 |