Wrox Programmer Forums
|
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
 
Old October 7th, 2009, 01:21 PM
Friend of Wrox
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow 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....
 
Old October 7th, 2009, 01:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.....
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 7th, 2009, 01:55 PM
Friend of Wrox
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow 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);
	    }
	}
 
Old October 7th, 2009, 02:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 7th, 2009, 02:07 PM
Friend of Wrox
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow 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;
 
Old October 7th, 2009, 02:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't understand your first question.

-1 is necessary to take the GridView out of edit mode....
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 7th, 2009, 02:25 PM
Friend of Wrox
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow list item

OK, please tell me that How I can change the currency symbol i.e. from $ to something else.
 
Old October 7th, 2009, 03:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Wish list in webshop ashwinirajp BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 September 22nd, 2009 02:42 AM
Invisible List Item? The Duke ASP.NET 3.5 Professionals 0 September 1st, 2008 12:14 PM
Get the first item of a List hpox ASP.NET 2.0 Basics 1 February 16th, 2007 06:04 PM
Adding List Item Programmatically rit01 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 February 12th, 2006 04:51 PM
How to populate list item shankhan Classic ASP Databases 5 March 23rd, 2005 04:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.