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

change values in radgrid field according to changes in another field

19 Answers 940 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lekha
Top achievements
Rank 1
lekha asked on 01 Jun 2009, 05:33 AM
i am having radgrid with some fields as  grid bound column and some fields numerictextboxes. I want to multiply one boundfield column(total Quantity) and 2 numerictextboox fields(NoOfDays,Price/Unit)and get the result on another numerictextbox(TotalPrice)  the numeric textboxes are editable and boundfield loaded as per query....and the sum of total price(TotalPrice) to be calculated as footer.......I tried as per the demo and i got the footer values .but i dont know how to multiply the boundfield value using script. which is the event fired on boundfield using script??

19 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 03 Jun 2009, 02:52 PM
Hi lekha,

Our Calculated Columns Demo demonstrates how you can use a readily available GridCalculatedColumn to calculate values horizontally.

On the other side, I couldn't quite get what you need to do using client script. Do you need to calculate a cell value after a client event, or you need your values calculated on the client on initial grid load?

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
lekha
Top achievements
Rank 1
answered on 04 Jun 2009, 11:50 AM
thanks for your answer. I need to calculate a cell value after a client event,I want to multiply one boundfield colmn value(Total Quantity) and two editable textbox fields(number of days and price/unit) in same row and display result another textbox (total price)in same row.,And sum of total price column must displayed as footer.On each row  editing this footer must change.Hope you understand my question.
Thank you
0
Veli
Telerik team
answered on 09 Jun 2009, 01:58 PM
Hello lekha,

I have created a sample project you can test to see how RadGrid's and RadInput's client-side APIs work together to achieve this scenario.

We use RadGrid's client-side OnGridCreated event to find each textbox in each field, retrieve their values and calculate totals. An interesting thing to note is that, as we use RadNumericTextBox for better numeric formatting and presentation, we need to set its value through the client API's set_value() method. Otherwise, RadInput's value cannot be properly set.

Additionally, we use RadNumericTextBox's OnBlur client event to recalculate the totals after each multiplier textbox is blurred.

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
lekha
Top achievements
Rank 1
answered on 15 Jun 2009, 07:29 AM
Thanks for your Answer. Its very helpful for me..Hope This may help several .......

thanks telerik team
lekha
0
lekha
Top achievements
Rank 1
answered on 18 Jun 2009, 05:07 AM
I have one more doubt relating this topic...Here I am editing grid template fields  at client side..And at the time I want to delete one row at client side.I deleted that row and rebind the sessiondatatable to the radgrid... using the code below,....
The problem is after rebinding edited datas are cleared..... i have to persist the edited datas to the sessiondatatable.........Please share suggessions..

protected void RadGrid_DeleteCommand(object source, GridCommandEventArgs e)
  {
 cSessionHandler.dtRequestDetails.Rows.RemoveAt(Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["SlNo"]));
  }



lekha
0
Sebastian
Telerik team
answered on 18 Jun 2009, 07:44 AM
Hello lekha,

The new values entered on editing are cleared when you explicitly rebind the grid since they were not injected in the underlying source and the old values are fetched from there when the grid is bound. If you would like to keep them, you should either update the source before the delete operation takes place or notify the user that any unsaved data will be lost when he/she triggers delete action.

Regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
lekha
Top achievements
Rank 1
answered on 18 Jun 2009, 09:59 AM
Thank you
0
lekha
Top achievements
Rank 1
answered on 05 Aug 2009, 12:54 PM
hai,
      I want to save the footer value of the total price field in this example....i save the footer value by assigning its value to a hiddenfield and save.Its working but problem is when i change the page index of the grid the footer value is to be added.......I did and its working

If there is any other simple and good way please give suggessions..............

thanks telerik team
0
lekha
Top achievements
Rank 1
answered on 04 Feb 2010, 08:58 AM
hi all,
I have a doubt relating this .in my grid on textbox editing calculated values appear on footer totalprice textbox but respective to pagesize ie,my grid page size is 4, And in first page if 4 items and in second page if 2 items, I am getting totalprice of 4 items in first page and total price of 2 items in second page. .But i need totalprice too. irrespective of pagesize ie.Totalprice of 6 items.Is there any way to get the total?

Thanks In advance
lekha

0
Sebastian
Telerik team
answered on 04 Feb 2010, 09:33 AM
Hello lekha,

Indeed only the values on the current page can be calculated because they are available on the active page. If you would like to display totals spanning different pages, you will need to implement that with your own custom logic (accessing directly the data source of the grid) or, alternatively, disable paging in case you do not have very large number of records.

Kind regards,
Sebastian
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
lekha
Top achievements
Rank 1
answered on 04 Feb 2010, 09:54 AM
Thank you
0
lekha
Top achievements
Rank 1
answered on 07 Jun 2010, 08:27 AM

0
Robert
Top achievements
Rank 2
answered on 13 Jan 2012, 04:08 PM
hi everybody i have a similar case i have to multiply 2 columns for give me a total price,  i only retrieve 2 field of my data base code and product name,  and i created 3 field in the radgrid : units, price and total, this field i can edit so i need  a textbox in my grid, but what i have to do for refresh values in the radgrid for a new multiply with my new values in units, price and totals, by the moment i am using:

 <telerik:GridCalculatedColumn HeaderText="Valor Total" UniqueName="TotalPrice" DataType="System.Double"
                        DataFields="unit, price" Expression="{0}*{1}" FooterText="Total : "
                        Aggregate="Sum" />         

for calculate the total.
and i was trying solution here with BusinessObjectCollection but i don know how to work i am new programming on asp.net and teleriks controls but i hope anybody can help me
0
Veli
Telerik team
answered on 16 Jan 2012, 10:28 AM
Hi Robert,

Is the example I posted some time ago not working for you? It demonstrates the same behavior you are describing.

Veli
the Telerik team
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 their blog feed now
0
Robert
Top achievements
Rank 2
answered on 16 Jan 2012, 03:20 PM
thank u its working right now :)
0
Robert
Top achievements
Rank 2
answered on 20 Jan 2012, 12:40 AM
Hi again, i have a little question more

i am trying to  save some field of my radgrid, but i have had problems with
this is my code:

Private Function retaceo_detalle(ByRef idretaceo As Integer) As Boolean
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "sp_s_ingresoretaceo"
        cmd.Connection = Conn
        Conn.Open()

        For Each dataItem As GridDataItem In RadGrid1.Items
            Try
                Dim txt1 As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("unidadesTextBox"), RadNumericTextBox)
                Dim txt2 As RadNumericTextBox = DirectCast(dataItem("Price").FindControl("ValorUnitarioTextBox"), RadNumericTextBox)
                RadTextBox7.Text = txt1.Text
                RadTextBox8.Text = txt2.Text

                cmd.Parameters.Add("@factura", SqlDbType.Int).Value = RadTextBox9.Text
                cmd.Parameters.Add("@matprim", SqlDbType.Text).Value = dataItem("COD_MATPRIMA").Text
           --> cmd.Parameters.Add("@cantidad", SqlDbType.Decimal).Value = RadTextBox7.Text
           --> cmd.Parameters.Add("@vunitario", SqlDbType.Money).Value = RadTextBox8.Text
                cmd.Parameters.Add("@codigo", SqlDbType.Int).Value = CType(id_retaceo, Integer)
                cmd.ExecuteNonQuery()
                cmd.Parameters.Clear()

            Catch ex As Exception
            End Try
        Next
        cmd.Connection.Close()
    End Function
so its save all information but the information that i trying to get of my radgrid does not work, the value return is  "" or 0 in the case that put a default value of 0 in the radnumeric properties but when i change this value, not show me the value changed... always 0 or ""

this is a piece of my aspx:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
                Width="1300px" GridLines="None" Skin="Sunset">
                <MasterTableView ShowFooter="true">
                    <Columns>
                        <telerik:GridBoundColumn DataField="COD_MATPRIMA" HeaderText="CODIGO">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="NOMMATPRI" HeaderText="NOMBRE">
                        </telerik:GridBoundColumn>
 
                        <telerik:GridTemplateColumn UniqueName="Quantity" HeaderText="UNIDADES">
                            <ItemTemplate>
                                <telerik:RadNumericTextBox DataType="System.Decimal" Value="0" ID="unidadesTextBox" runat="server"  Width="75">
                                    <NumberFormat   />
                                    <ClientEvents  OnBlur="recalculate" />
                                </telerik:RadNumericTextBox>
                            </ItemTemplate>
                            
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="Price" HeaderText="VALOR UNITARIO">
                            <ItemTemplate>
                                <telerik:RadNumericTextBox DataType="System.Decimal" ID="ValorUnitarioTextBox" Value="0" runat="server" Width="75">
                                    <NumberFormat  DecimalDigits="2" />
                                    <ClientEvents OnBlur="recalculate" />
                                </telerik:RadNumericTextBox>
                            </ItemTemplate>
                            <FooterTemplate>
                                Total:
                            </FooterTemplate>
                        </telerik:GridTemplateColumn>
.
.
.
.
.
0
Veli
Telerik team
answered on 20 Jan 2012, 10:53 AM
Hello Robert,

The code you posted seems fine and I cannot identify what may be causing this issue. Consider opening a regular support ticket where you can send us a sample application demonstrating this scenario. Thus, we will be able to better understand your case and advise you further.

Veli
the Telerik team
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 their blog feed now
0
Robert
Top achievements
Rank 2
answered on 20 Jan 2012, 03:18 PM
:( yes i dont understand the code is the same for calculate columns thta u give me i dont know why not get the value is how radgrid value is empty
0
Robert
Top achievements
Rank 2
answered on 22 Jan 2012, 05:58 AM
Veli i have a new question i have a problem when i multiply ... i put a value for example 1,000 on quantity and 1 on price the total give me is 1 :S, the function work if i put under 1000

var quantity = ParseFloat(items[i]._element.cells[2].getElementsByTagName('input')[0].value);
var price= ParseFloat(items[i]._element.cells[3].getElementsByTagName('input')[0].value);
var total = price * quantity;
Tags
Grid
Asked by
lekha
Top achievements
Rank 1
Answers by
Veli
Telerik team
lekha
Top achievements
Rank 1
Sebastian
Telerik team
Robert
Top achievements
Rank 2
Share this question
or