This is a migrated thread and some comments may be shown as answers.

radgrid Textbox data remain after postback

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 10 Oct 2013, 10:09 AM
Hi,
Iam using Radgrid for ASP.NET project.
In my grid i have 3 textbox column
for Qty,Price and Total Amont as textbox.
Using clientscript i do calculate on Qty*Price textbox value and update the result in Total Amount text box.

upto this its works fine.
but when i click some button ,using Pagin or during postback the new changed value is not displaying.

My code:
in Item data Bound:
 txtQty.Attributes.Add("onFocusout", "return calculate('" + txtQty.ClientID + "','" + txtamnt.ClientID + "','" + txttotamnt.ClientID + "'," + index + ")");
            txtamnt.Attributes.Add("onFocusout", "return calculate('" + txtQty.ClientID + "','" + txtamnt.ClientID + "','" + txttotamnt.ClientID + "'," + index + ")");
            txttotamnt.Attributes.Add("onfocus", "return calculate('" + txtQty.ClientID + "','" + txtamnt.ClientID + "','" + txttotamnt.ClientID + "'," + index + ")");


and my javascript.
 function calculate(cntl1, cntl2, cntl3,rowindex)
           {
                var text1 =$find(cntl1);
                var text2 =$find(cntl2);
                var text3 = $find(cntl3);
               // alert(rowindex);
                var total = text1.get_value() * text2.get_value();
                text3.set_value(total);
                radGrid.MasterTableView.get_dataItems()[rowindex].get_cell("displayAmnt").innerHTML = total;
            }

how to achive textbox Value change value using client side and presist the value.

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 15 Oct 2013, 07:13 AM
Hi Syed,

Actually you can calculate the value on the server in the OnItemDataBound event handler and set it to the Total Amount text box. By following this approach you will avoid attaching client-side event handlers and executing additional logic. The mentioned can be achieved by using the code shown below:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (item != null)
        {
            int qty = int.Parse((item["QtyColumnName"].FindControl("YourQtyTextBoxID") as TextBox).Text);
            int price = int.Parse((item["PriceColumnName"].FindControl("YourPriceTextBoxID") as TextBox).Text);
            (item["TotalColumnName"].FindControl("TotalColumnTextBoxId") as TextBox).Text= (qty * price).ToString();
        }
    }

Note that you should replace the columns unique names and text boxes ids. If this approach did not prove helpful please show us the columns definitions so we could provide a more accurate answer.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Syed
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or