hello.. i am using gridview control and as a datasource i use sql datasource...
here is the code of cart.aspx:
|
<%--
--%>
SelectCommand="SELECT * FROM [tmp]"
in the .cs file...
|
when user edit quantity it updated... bt how to update the price as well..?
17 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Kirtan PatelPosted Oct 16, 2009, 10:42 AM
SqlConnection con = new SqlConnection("Connection String");
SqlCommand comm = new SqlCommand("select sum(qnt*price) as 'All total' from products)",con);
double TotalofAll = Convert.ToDouble(comm.ExecuteScalar());
label1.Text = TotalofAll.ToString();
Dipa AhujaPosted Oct 17, 2009, 2:48 PM
n ya i never 4get to mark that if my problem is solved
Dipa AhujaPosted Oct 16, 2009, 10:13 AM
Dipa AhujaPosted Oct 16, 2009, 10:01 AM
i 4got 2 remove old code.... ur trick worked
thanks soooooooooooooooooo much
Kirtan PatelPosted Oct 16, 2009, 10:00 AM
if you still having problem then
don't mind, send me your project in mail ( [email protected])
i will solve it in minutes and send back your project after correcting it as what i want to explain to you, you not
understanding by my post here :)
Dipa AhujaPosted Oct 16, 2009, 9:55 AM
same prblm
when
price=1000 qnt=1 and when set qty=2 , price becomes 2000 as per the qty*price equation..
now qty is 2 and price =2000
bt what when qty changes from 2 to 1 then
it qty*price=1*2000 = 2000?? and also when qty set=3 it wil do 2000*3
i am confused.. any one can tell me.. how to solve this??
Kirtan PatelPosted Oct 16, 2009, 9:30 AM
select purl, code, pname, price, qty, (qty*price) as 'tot' from product
Here 'tot' is in Single Quotes :-)
and you also have to add One more Column to Data Grid View
Dipa AhujaPosted Oct 16, 2009, 9:25 AM
good suggession ..
so query for sqldatasource should be like this way?
select purl, code, pname, price, qty, (qty*price)as tot from product
i am trying ur suggession
Dipa AhujaPosted Oct 16, 2009, 9:14 AM
i did as u said.. it works well bt only once
becoz
>>>> when
price=1000 qnt=1 and when set qty=2 , price becomes 2000 as per the qty*price equation..
now qty is 2 and price =2000
bt what when qty changes from 2 to 1 then
it qty*price=1*2000 = 2000?? and also when qty set=3 it wil do 2000*3
i am confused.. any one can tell me.. how to solve this??
jingePosted Oct 16, 2009, 8:56 AM
Kirtan PatelPosted Oct 16, 2009, 8:53 AM
like when you fill grid from database
use query like
select ProductImage,Code,Qnt,Price,(Price*Qnt) as 'Net Price' from Products
so it will solve you all problems you don't have to manually count the Total Price every time it will be done automatically inside the select query
jingePosted Oct 16, 2009, 8:46 AM
But not sure with GridView in Asp.net. Maybe Ajax can help you?
he he..
Nilanka DharmadasaPosted Oct 16, 2009, 8:43 AM
// comm.Parameters.AddWithValue("@price",Convert.ToDouble(newprice.ToString()));
comm.Parameters.Add( "@price", SqlDbType.Decimal).Value = Convert.ToDouble(newprice.ToString());
Dipa AhujaPosted Oct 16, 2009, 8:40 AM
suppose if anyone have add "item1" of price Rs 500,
then when user update qnty as 2 then price should be updated by itself as
newprice=qty*price that measn 500*2=1000
and again when user change qnty from 2 to one then it should be 1000/2 and so on...
Roei BarPosted Oct 16, 2009, 8:38 AM
jingePosted Oct 16, 2009, 8:37 AM
Kirtan PatelPosted Oct 16, 2009, 8:34 AM
name of texbox is "txtPrice" so find control with that name :-) simple !! :)
below is corrected code :) chek it out :) if any problem ancounters let me know i will asssist you :-)