|
Subject:
|
values getting lost in button click
|
|
Posted By:
|
sarah lee
|
Post Date:
|
12/11/2006 2:44:54 PM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
12/11/2006 2:58:49 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
12/11/2006 3:05:35 PM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
12/11/2006 3:09:31 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
12/11/2006 3:35:41 PM
|
if i call the fillcartfromdb() from the button click, the application hangs.its not dispalying anything.
|
|
Reply By:
|
dparsons
|
Reply Date:
|
12/11/2006 3:44:55 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
12/11/2006 4:04:31 PM
|
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.
|
|
Reply By:
|
dparsons
|
Reply Date:
|
12/11/2006 4:11:29 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
12/11/2006 4:13:21 PM
|
thanks Parsons. i will step through the code in detail and try to figure out, if there is any infinite loop
|