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

RadGrid will not return cell modified value via JavaScript

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RUI_Dev
Top achievements
Rank 1
RUI_Dev asked on 10 Feb 2014, 06:39 PM
I built data entry form where user can type a numeric value and using JavaScript, it will update the rest of the grid and user will save the modified data from user entry and JS modification. The code was working under Win 7 x32bit.

I updated my OS to win 8 x64. After installing all the tools and moving the code from Win 7 to Win 8, I notice the code stop working. The code appeared to work correct when user enters data it auto calculated the cells with the JavaScript but when user click save only modified data by user is captured but javascript modified cells will not return the new value instead it return its original value.

I update my OS to be Win8 x32bit and retest the code and I found the issue still exists. Does RadGrid has issues with Win8?

I attached very simple example for the issue. Can you please help me figuring this issue out ?
 
ASP.NET CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<html5>
<head runat="server">
<title></title>
<telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<script type="text/javascript">
function OnBlurTxt(grid, args) {
var adj = document.getElementById('RadGrid1_ctl00_ctl04_txtPrice')
var adj2 = document.getElementById('RadGrid1_ctl00_ctl04_txtQnty')
var adj3 = document.getElementById('RadGrid1_ctl00_ctl04_txtTotal')
adj3.value = adj.value * adj2.value

}
</script>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableHistory="True" ViewStateMode="Enabled">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelCssClass="" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="Button1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelCssClass="" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div>

</div>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" AllowAutomaticUpdates="True">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="Name" AllowAutomaticUpdates="true">
<Columns>
<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Price" SortExpression="Price" UniqueName="Price" >
<ItemTemplate>
<telerik:RadNumericTextBox runat="server" NumberFormat-DecimalDigits="0" ID="txtPrice" Width="60px" DbValue='<%# Bind("Price") %>'
BackColor="Yellow" EnabledStyle-HorizontalAlign="Right" ViewStateMode="Enabled">
<ClientEvents OnBlur="OnBlurTxt" />
</telerik:RadNumericTextBox>
</ItemTemplate>
<ItemStyle Width="75px" HorizontalAlign=Right />
<HeaderStyle Width="75px" HorizontalAlign=Center />
</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn HeaderText="Qnty" SortExpression="Qnty" UniqueName="Qnty" >
<ItemTemplate>
<telerik:RadNumericTextBox runat="server" NumberFormat-DecimalDigits="0" ID="txtQnty" Width="60px" DbValue='<%# Bind("Qnty") %>'
BackColor="Yellow" EnabledStyle-HorizontalAlign="Right" ViewStateMode="Enabled">
<ClientEvents OnBlur="OnBlurTxt" />
</telerik:RadNumericTextBox>
</ItemTemplate>
<ItemStyle Width="75px" HorizontalAlign=Right />
<HeaderStyle Width="75px" HorizontalAlign=Center />
</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn HeaderText="Total" SortExpression="Total" UniqueName="Total">
<ItemTemplate>
<telerik:RadNumericTextBox runat="server" NumberFormat-DecimalDigits="3" ID="txtTotal" Width="60px" DbValue='<%# Bind("total") %>' BackColor="Yellow"
EnabledStyle-HorizontalAlign="Right" ViewStateMode="Enabled">
<ClientEvents OnBlur="OnBlurTxt" />
</telerik:RadNumericTextBox>
</ItemTemplate>
<ItemStyle Width="75px" HorizontalAlign=Right />
<HeaderStyle Width="75px" HorizontalAlign=Center />
</telerik:GridTemplateColumn>

</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RU_EnterpriseConnectionString %>" SelectCommand="SELECT [BrandID], [Name], [BrandOrderID] FROM [tblBrands]"></asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
</body>
</html5>


C# code
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Price");
dt.Columns.Add("Qnty");
dt.Columns.Add("Total");

object[] obj = new object[4] { "Test", "10", "5", "50" };
dt.Rows.Add(obj);
RadGrid1.DataSource=dt;
RadGrid1.Rebind();

}
}

protected void Button1_Click(object sender, EventArgs e)
{
//7-8-4
int i = 0;
string str="";
if (this.RadGrid1.Items[0] != null)
{

GridDataItem item = this.RadGrid1.Items[i];
RadNumericTextBox price = (RadNumericTextBox)item.Cells[3].FindControl("txtPrice");
RadNumericTextBox qnty = (RadNumericTextBox)item.Cells[4].FindControl("txtQnty");
RadNumericTextBox ttl = (RadNumericTextBox)item.Cells[4].FindControl("txtQnty");

str="Price="+price.Value.ToString() +" qnty=" +qnty.Value.ToString() + " ttl="+ttl.Value.ToString();

}

RadAjaxManager1.Alert(str);

}
}

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Feb 2014, 01:15 PM
Hello,

Please try with the below link/code.
Access Another control which was in same level or in row

function OnBlurTxt(sender, args) {
    var senderId = sender.get_id();
    var senderName = "";
    if (senderId.indexOf("txtPrice") > 0) {
        senderName = "txtPrice";
    }
    else if (senderId.indexOf("txtQnty") > 0) {
        senderName = "txtQnty";
    }
    else if (senderId.indexOf("txtTotal") > 0) {
        senderName = "txtTotal";
    }
    
    var txtx1 = $telerik.findNumericTextBox(senderId.replace(senderName, "txtPrice"));
    var txtx2 = $telerik.findNumericTextBox(senderId.replace(senderName, "txtQnty"));
    var txtx3 = $telerik.findNumericTextBox(senderId.replace(senderName, "txtTotal"));
 
    txtx3.set_value(txtx1.get_value());
 
 
}


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
RUI_Dev
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or