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

NumericTextBox set Value to 0.00 if users enters null value, but do totals with value from other column.

1 Answer 246 Views
Input
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 22 Sep 2014, 08:40 PM
Folks using VStudio 2010 with UI for ASP.NET AJAX Q2 2014 SP1.
I have 3 RadNumericText Boxes (txtRadOriginalPages, txtRadCopies and txtRadCopyQty1) in a Form.
Basically it does do Client Side Total based on txtRadOriginalPages &  txtRadCopies  and populate txtRadCopyQty1. 
I would like to Populate txtRadCopies with 0.00 if it is null and populate the Total txtRadCopyQty1 from the Value of txtRadOriginalPages in Client Side.
Below is my complete Code Description and attached is my desired result. 

Thanks for any help.

gc_0620

<%@ Page Language="C#" %>
 
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script runat="server">
 
  
 
    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        DataTable dt = new DataTable();
 
        DataRow dr;
 
        int colsNum = 4;
 
        int rowsNum = 5;
 
        string colName = "Column";
 
 
 
        for (int j = 1; j <= colsNum; j++)
        {
 
            dt.Columns.Add(String.Format("{0}{1}", colName, j));
 
        }
 
 
 
        for (int i = 1; i <= rowsNum; i++)
        {
 
            dr = dt.NewRow();
 
 
 
            for (int k = 1; k <= colsNum; k++)
            {
 
                dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
 
            }
 
            dt.Rows.Add(dr);
 
        }
 
 
 
        (sender as RadGrid).DataSource = dt;
 
    }
 
      
 
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head id="Head1" runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Transparency="50"
        BackColor="Yellow" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" OnNeedDataSource="RadGrid_NeedDataSource">
        <MasterTableView EditMode="EditForms">
            <EditFormSettings EditFormType="Template" />
            <EditFormSettings>
                <FormTemplate>
                    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                        <script type="text/javascript">
 
 
 
                            //Calculate the original pages * the copies and input the result to copy quantity 
 
                            var ActualIndex;
 
                            var index;
 
                            var txtRadOriginalPages = null;
 
                            var txtRadCopies = null;
 
                            var txtRadCopyQty1 = null;
 
 
 
                            function updateTotals(sender, args) {
 
                                var v1 = txtOriginalPages.get_value();
 
                                var v2 = txtCopies.get_value();
 
                                var finalValue = parseFloat(v1) + parseFloat(v2);
 
                                txtRadCopyQty1.set_value(parseFloat(finalValue));
 
                            }
 
                            function setIndex(sender, args) {
 
                                index = args.get_itemIndexHierarchical();
 
                            }
 
                            function setActualIndex() {
 
                                ActualIndex = index;
 
                            }
 
                            function Load1(sender, args) {
 
                                txtOriginalPages = sender;
 
                            }
 
                            function Load2(sender, args) {
 
                                txtCopies = sender;
 
                            }
 
                            function Load3(sender, args) {
 
                                txtRadCopyQty1 = sender;
 
                            }
 
  
 
                        </script>
                    </telerik:RadScriptBlock>
                    <table>
                        <tr>
                            <td align="left">
                                <asp:Label ID="lblOriginalPages" runat="server" Text="Original Pages:"></asp:Label>
                            </td>
                            <td align="left">
                                <telerik:RadNumericTextBox ID="txtRadOriginalPages" runat="server" NumberFormat-DecimalDigits="2"
                                    NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                    NumberFormat-AllowRounding="true" Type="Number">
                                    <ClientEvents OnValueChanged="updateTotals" OnFocus="setActualIndex" OnLoad="Load1" />
                                </telerik:RadNumericTextBox>
                            </td>
                            <td align="left">
                                <asp:Label ID="lblCopies" runat="server" Text="Copies:"></asp:Label>
                            </td>
                            <td align="left">
                                <telerik:RadNumericTextBox ID="txtRadCopies" runat="server" NumberFormat-DecimalDigits="2"
                                    NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                    NumberFormat-AllowRounding="true" Type="Number">
                                    <ClientEvents OnValueChanged="updateTotals" OnFocus="setActualIndex" OnLoad="Load2" />
                                </telerik:RadNumericTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="lblCopyQty1" runat="server" Text="Original Pages + Copy:"></asp:Label>
                            </td>
                            <td align="left">
                                <telerik:RadNumericTextBox ID="txtRadCopyQty1" runat="server" NumberFormat-DecimalDigits="2"
                                    NumberFormat-DecimalSeparator="." NumberFormat-GroupSeparator="," NumberFormat-GroupSizes="3"
                                    NumberFormat-AllowRounding="true" Type="Number">
                                    <ClientEvents OnLoad="Load3" />
                                </telerik:RadNumericTextBox>
                            </td>
                            <td align="left">
                                <asp:Label ID="lblInkType1" runat="server" Text="Ink Type 1:"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" colspan="6">
                                <asp:ImageButton ID="ImageButtonDemoMainUpdateInsert" ToolTip='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                    runat="server" ImageUrl="~/Images/GridUpdateEditInsert.gif" />
                                <asp:ImageButton ID="ImageButtonDemoMainCancelUpdateInsert" ToolTip="Cancel" CommandName="Cancel"
                                    CausesValidation="false" runat="server" ImageUrl="~/Images/GridCancelEditInsert.gif" />
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
    </form>
</body>
</html>
 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 25 Sep 2014, 11:24 AM
Hello,

I have tested the scenario that you have on my end and having in mind your requirement, could you please apply the following change within the Load2 handler and see if that is the result that you need to achieve:
function Load2(sender, args) {
    txtCopies = sender;
    if (!sender.get_value()) {
        setTimeout(function () {
            sender.set_value(0);
        });
    }
}

Let me know if there are other questions on this matter.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Input
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or