Click here to Skip to main content
14,691,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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.

Thanks


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();
            labelamount.Setvalue(total);
             }


    </script>

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();
               da.Fill(ds);
               list.DataSource = ds;
               list.DataBind();

               //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???
Posted
Updated 2-Mar-11 14:29pm
v3

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;

}
   
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.
   
Comments
call to .net 27-Oct-10 7:33am
   
thanks
raju melveetilpurayil 27-Oct-10 10:41am
   
good one
Hi,
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.
   
:confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:
   

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