At my GRIDVIEW I have 2 columns namely "unit price" and "quantity".
I want to display the product of these 2 columns in another field called "amount" on the GRIDVIEW.
I wish to display the calculated value in this third column once the user lost focus from “unit price” or “quantity”.
I will appreciate urgent help...please.
If you want to save the data to a MS SQL DB, I would suggest using a simple stored procedure. Then what you can do is databind the gridview to the SP and there you have it. You can save the data with virtually no code other than the SP.
If you have any ?'s on this, let us know
thnx,
Mark As Answer If this has helped you
Remember to "Mark As Answer" if this post has helped you! Thanks....
And I say unto you, Ask, and it shall be given you; seek, and ye shall find; knock, and it shall be opened unto you...
LK 11:9
http://adventwebdesign.net
Marked as answer by patuary on Aug 15, 2007 10:41 AM
.... now another problem. at page load event i bound salesAmount column by 0(Grid View)...
You need to keep your page load event code to bound salesAmount column in an IsPostBack check
void Page_Load(.....)
{
if ( ! Page.IsPostBack )
{
// write your code here to bound the salesAmount
}
}
When you try to save the new calculated values, on the insert/update command, the page_load will be called first and your values are getting reset. If you use the PostBack check, the code is executed only the first time and not on subsequent postback's
patuary
Member
425 Points
143 Posts
about gridview - -new help
Jun 20, 2007 10:26 AM|LINK
At my GRIDVIEW I have 2 columns namely "unit price" and "quantity".
I want to display the product of these 2 columns in another field called "amount" on the GRIDVIEW.
I wish to display the calculated value in this third column once the user lost focus from “unit price” or “quantity”.
I will appreciate urgent help...please.
e_screw
All-Star
19530 Points
3894 Posts
Re: about gridview - -new help
Jun 20, 2007 12:14 PM|LINK
Check the solution for a similar question at http://forums.asp.net/p/1100193/1670896.aspx#1670896
Thanks
Electronic Screw
Website||Blog||Dub@i.net
patuary
Member
425 Points
143 Posts
Re: about gridview - -new help
Jun 20, 2007 06:04 PM|LINK
Thanks... thanks a lot.....
now i am at another problem. i want to save data to database from that gridview. can u help me by giving c# code?
revkev
Participant
1501 Points
386 Posts
Re: about gridview - -new help
Jun 20, 2007 08:39 PM|LINK
patuary,
If you want to save the data to a MS SQL DB, I would suggest using a simple stored procedure. Then what you can do is databind the gridview to the SP and there you have it. You can save the data with virtually no code other than the SP.
If you have any ?'s on this, let us know
thnx,
Mark As Answer If this has helped you
And I say unto you, Ask, and it shall be given you; seek, and ye shall find; knock, and it shall be opened unto you...
LK 11:9
http://adventwebdesign.net
patuary
Member
425 Points
143 Posts
Re: about gridview - -new help
Jun 21, 2007 01:17 AM|LINK
thanks... can u provide me C# code??
e_screw
All-Star
19530 Points
3894 Posts
Re: about gridview - -new help
Jun 21, 2007 05:12 AM|LINK
Check Data Tutorials of this site.
Thanks
Electronic Screw
Website||Blog||Dub@i.net
patuary
Member
425 Points
143 Posts
Re: about gridview - -new help
Jun 21, 2007 08:23 AM|LINK
thanks a lot again.... now another problem. at page load event i bound salesAmount column by 0(Grid View)...
when i want to save data to database the new calculated value(sales qty*price per qty) does not save... the default value doing save!!!!!
e_screw
All-Star
19530 Points
3894 Posts
Re: about gridview - -new help
Jun 23, 2007 05:11 AM|LINK
You need to keep your page load event code to bound salesAmount column in an IsPostBack check
void Page_Load(.....)
{
if ( ! Page.IsPostBack )
{
// write your code here to bound the salesAmount
}
}
When you try to save the new calculated values, on the insert/update command, the page_load will be called first and your values are getting reset. If you use the PostBack check, the code is executed only the first time and not on subsequent postback's
Thanks
Electronic Screw
Website||Blog||Dub@i.net
patuary
Member
425 Points
143 Posts
Re: about gridview - -new help
Jun 23, 2007 12:43 PM|LINK
yes i did it......... BUT still remain same...
I cant understand what is the problem....... this problem is also to others 0 default valued fields...
string strSQL = "", strCon = "";
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
//GET CONNECTED
strCon = ConfigurationManager.ConnectionStrings["DB_OrderConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strCon);
con.Open();
//GET SERVER DATE
//this.lblEntryDate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
//GET PRODUCT INFO
strSQL = "SELECT intProductCode, strProductName as ProductName, SKU, Pack, intQtyPerCase AS QtyPerCase, mnyCasePrice,
0 as QtyToDeliv, 0 as BonusQty, 0 as SalesAmnt, intBonusQtyPerCase FROM tblProductInfo ORDER BY strProductName, intProductCode";
SqlCommand cmdP = new SqlCommand(strSQL, con);
SqlDataAdapter AdapterP = new SqlDataAdapter(cmdP);
DataTable dtProduct = new DataTable();
AdapterP.Fill(dtProduct);
this.GVChallanEntry.DataSource = dtProduct;
this.GVChallanEntry.DataBind();
cmdP.Cancel();
cmdP.Dispose();
//CLOSE CONNECTION
con.Close();
}
}
catch (Exception ex)
{
lblErr.Text = ex.Message;
if (lblErr.Text == "Line 1: Incorrect syntax near '='.")
Response.Redirect("ChallanEntryScreen01.aspx");
else
lblErr.Text = ex.Message;
}
}
patuary
Member
425 Points
143 Posts
Re: about gridview - -new help
Dec 25, 2007 09:54 AM|LINK
i have solved this problem myself... thanks for help