Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to calculate two column inside grid-view and calculation should come in third column.
i have rate of item from database and user input quantity on the basis of
both column make calculation and display in third column amount.

here is it possible when user insert value in quantity same time amount column display calculation of rate and amount.


my function is

<script type="text/javascript" language="javascript">
        function show(labelrate, labelamount, txtqty) {
            var txt_Quantity = $find(txtqty);
            var lbl_Rate = $find(labelrate)
            var lbl_Amount = $find(labelamount);
            //lbl_Amount.innerHTML = parseInt(txt_Quantity.get_value()) * parseInt(lbl_Rate.get_value());
            var total = txt_Quantity.Getvalue() * lbl_Rate.Getvalue();


protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
           if (e.Item is GridDataItem || e.Item.IsInEditMode)
               GridDataItem item = (GridDataItem)e.Item;
               DropDownList list = (DropDownList)item.FindControl("ddl1");
               list.Items.Insert(0, new ListItem("select", "-1"));
               SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["chalk_hillConnectionString"].ConnectionString);
               SqlDataAdapter da = new SqlDataAdapter();
               da.SelectCommand = new SqlCommand("select product_name from product_detail", con);
               DataSet ds = new DataSet();
               list.DataSource = ds;

               //For calculate item Amount....
               Label lbl_Rate = (Label)item.FindControl("lblRate");

               TextBox txt_Quantity = (TextBox)item.FindControl("txtQuantity");
               Label lbl_Amount = (Label)item.FindControl("lblAmount");

               txt_Quantity.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')");
               lbl_Rate.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')");
               lbl_Amount.Attributes.Add("onFocusout", "return show('" + txt_Quantity.ClientID + "','" + lbl_Rate.ClientID + "','" + lbl_Amount.ClientID + "')");


but this is unable to make calculation???
Updated 2-Mar-11 13:29pm

write a javascript and Use this script in onkeypress event to qnty textbox ... show the result in Result text box

function readQuantity(qty)
//get Price from price textbox

var price = getElementById('<%= priceTextBox.ClientID%>').value;
var Result = price * qty
return Result;

Share this answer
Well, at time of entering the data:
Have a Javascript method attached to the columns such that, once the data is entered into it, rate is filled up.

At time of pulling data from DB and showing it, use the two column values to calculate the rate in query itself.
Share this answer
call to .net 27-Oct-10 7:33am    
raju melveetilpurayil 27-Oct-10 10:41am    
good one
To display your calculation instantly in the third column you have to use the javascript.
You can place the textboxes in the tempelate field and register the client side script in the Row databound event of ur grid and pass the client id of textboxes in the client side js function at that time otherwise you face problem in resloving the ids of the textboxes placed in your grid.
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900