jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 4:37 AM EDT
0
What's the problem with your current code? Why not add one more code with "AddWithValue" to update the price column. Note you may need to caluclate the price based on the quatitiy...
or you can go to the db with the items and quantity and have it return the prices per each item by quantity.
0
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 4:40 AM EDT
0
bt i want the price to be updated by it self..
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...
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??
0
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 5:25 AM EDT
0
to Kirtan 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
0
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 5:30 AM EDT
0
Diya make Sure you Write Query Exactly Like below
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
0
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 5:55 AM EDT
0
to kirtan:
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??
0
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 6:00 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 6:42 AM EDT
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();
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 4:34 AM EDT
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 :-)
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { System.Web.UI.WebControls.TextBox TextBox1; TextBox1 = (System.Web.UI.WebControls.TextBox)GridView1.Rows[e.RowIndex].FindControl("txtqty"); // Add New Line Like Below System.Web.UI.WebControls.TextBox PriceTextBox; PriceTextBox = (System.Web.UI.WebControls.Label)GridView1.Rows[e.RowIndex].FindControl("txtPrice"); System.Web.UI.WebControls.Label Label3; Label3 = (System.Web.UI.WebControls.Label)GridView1.Rows[e.RowIndex].FindControl("lblcode"); objConnection.Open(); SqlCommand comm = new SqlCommand("UPDATE tmp SET qty=@qty,price=@price WHERE code=@code", objConnection); comm.Parameters.AddWithValue("@qty", TextBox1.Text.ToString()); // Add New Line Like Below comm.Parameters.AddWithValue("@price", PriceTextBox.Text); comm.Parameters.AddWithValue("@code", Label3.Text.ToString()); comm.ExecuteNonQuery(); //Finally Close the Connection objConnection.Close(); GridView1.EditIndex = -1; GridView1.DataBind(); }jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 4:37 AM EDT
Roei BarRank #1,271 · 1.4K reputationPosted Oct 16, 2009, 4:38 AM EDT
(int.parse(txtQuantity.Te) * float.parse(LblPrice.Text)).ToString();or you can go to the db with the items and quantity and have it return the prices
per each item by quantity.
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 4:40 AM EDT
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...
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Oct 16, 2009, 4:43 AM EDT
// comm.Parameters.AddWithValue("@price",Convert.ToDouble(newprice.ToString()));
comm.Parameters.Add( "@price", SqlDbType.Decimal).Value = Convert.ToDouble(newprice.ToString());
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 4:46 AM EDT
But not sure with GridView in Asp.net. Maybe Ajax can help you?
he he..
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 4:53 AM EDT
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
jingeRank #2,527 · 554 reputationPosted Oct 16, 2009, 4:56 AM EDT
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 5:14 AM EDT
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??
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 5:25 AM EDT
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
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 5:30 AM EDT
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 AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 5:55 AM EDT
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 PatelRank #292 · 8.6K reputationPosted Oct 16, 2009, 6:00 AM EDT
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 AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 6:01 AM EDT
i 4got 2 remove old code.... ur trick worked
thanks soooooooooooooooooo much
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 16, 2009, 6:13 AM EDT
Dipa AhujaRank #1,168 · 1.5K reputationPosted Oct 17, 2009, 10:48 AM EDT
n ya i never 4get to mark that if my problem is solved