 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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
|
|
|
|

December 11th, 2006, 03:44 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
values getting lost in button click
hi all,
i have a shopping cart, in which i can adjust qunatities,
when i edit quantity and then click the recalculate button, the values are lost from the datagrid, and also the total is shown as 0.00
given below is the code which i am using
can anyone please see and tell me, what is the mistake i hav done
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim total As Decimal = 0
Try
For Each dgi As DataGridItem In DataGrid1.Items
If dgi.ItemType = ListItemType.Item OrElse dgi.ItemType = ListItemType.AlternatingItem Then
Dim t As TextBox = CType(dgi.Cells(3).Controls(1), TextBox)
Dim quantity As Integer = Integer.Parse(t.Text)
Dim unitprice As Decimal = Decimal.Parse(dgi.Cells(2).Text)
total = total + (unitprice * quantity)
Dim ShopCart2 As ShoppingCart.shopcart = New ShoppingCart.shopcart
ShopCart2.UpdateQuantity(Session.SessionID, Integer.Parse(dgi.Cells(0).Text), quantity)
End If
Next
Catch ex As Exception
End Try
lblAmt.Text = total.ToString("c")
End Sub
and in the class
Public Sub UpdateQuantity(ByVal CartID As String, ByVal ProductID As Integer, ByVal newQty As Integer)
Dim con As New SqlConnection("")
Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandText = "update ShoppingCart set Quantity=@qty where CartID= @cartid and ProductID=@prodid"
Dim p1 As New SqlParameter("@qty", newQty)
Dim p2 As New SqlParameter("@cartid", CartID)
Dim p3 As New SqlParameter("@prodid", ProductID)
cmd.Parameters.Add(p1)
cmd.Parameters.Add(p2)
cmd.Parameters.Add(p3)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
THANKS
|
|

December 11th, 2006, 03:58 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
It doesnt appear that you are rebinding your data to anything...
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|

December 11th, 2006, 04:05 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i am sorry, i am actually rebinding using the below code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
FillCartFromDB()
End If
End Sub
Function FillCartFromDB()
Dim ds As New DataSet
ds = ShoppingCart.shopcart.GetAll(Session.SessionID)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Button1_Click(Nothing, Nothing)
End Function
|
|

December 11th, 2006, 04:09 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
You bind isn't called. Your button posts the page back to itself and the FillCart method is never called; call FillCartFromDB in your button_click event.
Also, you have labeled FillCartFromDB as a function, its a method because it doesnt return a value.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|

December 11th, 2006, 04:35 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
if i call the fillcartfromdb() from the button click, the application hangs.its not dispalying anything.
|
|

December 11th, 2006, 04:44 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Then something is wrong with how your are processing data and if it isnt throwing an error I couldn't even begin to tell you how to correct it.
What I can tell you with 100% certainity is that after you click the "recalculate" button is that the method FillCartFromDB is never called again. That will correct the problem of your datagrid not rebinding, however, you now need to figure out where your code is hanging out and why. Place a hook inside your class and step through your code and see what is going on.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|

December 11th, 2006, 05:04 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i tried once more giving the fillcartfromdb() in buttonclick
the error coming is
Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.
|
|

December 11th, 2006, 05:11 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
That message means: Your aspnet_wp.exe process on the server is crashing. This normally happens when the .NET worker process consumes to much server resource and the process gets recycled by the server automatically. In your case, this problem is *probably* occuring because you have entered into an infinte loop or some process that takes an extremely long time to complete and, moreover, is consuming vast amounts of memory in the process.
You are going to have to step through your code on this one because, outside of a speicific error, I can't provide you any more info.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|

December 11th, 2006, 05:13 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks Parsons.
i will step through the code in detail and try to figure out, if there is any infinite loop
|
|
 |