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

[Solved] GridCalculated Column inside a Template Column

4 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pooja
Top achievements
Rank 1
Pooja asked on 09 Apr 2013, 02:57 PM
I have a requirement where I need to  have a GridCalculated column inside a GridTemplateColumn. I tried to search online but could not an answer to it.
when I try to add it I get an error.
Is it possible to have a GridCalculatedColumn inside a GridTemplateColumn? If yes then I would need a way to update it client side if a User changes a value.

Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Apr 2013, 04:56 AM
Hi Pooja,

You can't put a GridCalculatedColumn inside the GridTemplateColumn. Try the calculations manually through code behind and show it using a label inside the GridTemplateColumn.

Thanks.
Princy.

0
Pooja
Top achievements
Rank 1
answered on 10 Apr 2013, 02:24 PM
Thanks Princy for answering my question. That makes me feel better becasue I tried everything.
I wanted the calculations to be dynamic so that the values get updated when user changes one of the value.

I have 4 TextBoxcontrols in a Grid Row. 3 of them are editable and 1 is a Readonly that will contain the calculated value.
 These are inside grid in different tempalte columns. I have added a clientevent for valuechanged which gets fired when the textbox value changes and user goes to next textbox.
The calculations go like this:

D = A>B? (A+C) : (B+C)

I was trying to accomplish this with jquery but I keep getting error when I try to

  function ValueChanged(sender, args) {
               var grid = $find("<%=rgMyGrid.ClientID %>");
 
 
               var totalAmount = 0;
 
               if (grid) {
                   var MasterTable = grid.get_masterTableView();
                   var Rows = MasterTable.get_dataItems();
                   for (var i = 0; i < Rows.length; i++) {
                       var row = Rows[i];
 
                       var Total= row.findControl("Total");
                       var A= row.findControl("A");
                       var B= row.findControl("B");
                       var C= row.findControl("C");
                       Total.value =  A>B? (A+C) : (B+C);

                                           }                }
This is the line where error happens. It is not able to find the Total Numeric textbox. The textbox //              var RadNumericTextBox1 = $find("<%=Total.ClientID %>"); //               RadNumericTextBox1.set_value(Total);            }
Could you please help me fix this?

Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Apr 2013, 05:06 AM
Hi Pooja,

I don't understand why are you accessing the 'Total' (RadNumericTextBox) again using the ClientID. You could set the the Calculated value in the Total RadNumericTextBox using 'set_value()' in each row. Please take a look into the following code snippet.

Javascript:
<script type="text/javascript">
    function OnValueChanged() {
        var grid = $find("<%=rgMyGrid1.ClientID %>");
        var totalAmount = 0;
        if (grid) {
            var MasterTable = grid.get_masterTableView();
            var Rows = MasterTable.get_dataItems();
            for (var i = 0; i < Rows.length; i++) {
                var row = Rows[i];
                var Total = row.findControl("Total");
                var A = row.findControl("A")._enteredText;
                var B = row.findControl("B")._enteredText;
                var C = row.findControl("C")._enteredText;
                var t = A > B ? (A + C) : (B + C);
                Total.set_value(t); //setting the calculated value of the row in the Total RadNumericTextBox
            }
        }
    }
</script>

Please elaborate the scenario if it doesn't help.

Thanks,
Princy.
0
Pooja
Top achievements
Rank 1
answered on 11 Apr 2013, 06:02 PM
Thanks Princy. This answer worked with a small change. I hhad to use the following code :
<script type="text/javascript">
    function OnValueChanged() {
        var grid = $find("<%=rgMyGrid1.ClientID %>");
        var totalAmount = 0;
        if (grid) {
            var MasterTable = grid.get_masterTableView();
            var Rows = MasterTable.get_dataItems();
            for (var i = 0; i < Rows.length; i++) {
                var row = Rows[i];
                var Total = row.findControl("Total");
                var A = row.findControl("A").get_value();
                var B = row.findControl("B").get_value();
                var C = row.findControl("C").get_value();
                var t = A > B ? (A + C) : (B + C);
                Total.set_value(t); //setting the calculated value of the row in the Total RadNumericTextBox
            }
        }
    }
</script>

Thanks for your help.

Regards
Tags
Grid
Asked by
Pooja
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pooja
Top achievements
Rank 1
Share this question
or