ServerAddRow can not get all column value

my aspx

<ej:Grid ID="grdPurchaseWHTIncome"
                                    runat='server'
                                    MinWidth="600"
                                    EnableTheming="true"
                                    IsResponsive="true"
                                    AllowScrolling="true"
                                    AllowSorting="true"
                                    AllowMultiSorting="true"
                                    AllowResizing="true"
                                    AllowPaging="false"
                                    EnableTouch="true"
                                    GridLines="None" 
                                    OnServerAddRow="grdPurchaseWHTIncome_ServerAddRow" 
                                    OnServerEditRow="grdPurchaseWHTIncome_ServerEditRow" 
                                    OnServerDeleteRow="grdPurchaseWHTIncome_ServerDeleteRow">
                                    <Columns>
                                        <ej:Column HeaderText="ประเภทเงินได้" Field="WHTCode" TextAlign="Left" AllowEditing="true" IsPrimaryKey="true">
                                             <EditTemplate Create="create" Read="readPurchaseWHTCode" Write="writePurchaseWHTCode" />
                                        </ej:Column>
                                        <ej:Column HeaderText="จำนวนเงินได้" Field="WHTAmount" DataType="Decimal" TextAlign="Right" AllowEditing="true" Format="{0:n2}">
                                             <EditTemplate Create="create" Read="readPurchaseWHTAmount" Write="writePurchaseWHTAmount" />
                                        </ej:Column>
                                        <ej:Column HeaderText="อัตราภาษี" Field="WHTPercent" DataType="Decimal" TextAlign="Right" AllowEditing="true" Format="{0:n2}"></ej:Column>
                                        <ej:Column HeaderText="มูลค่าภาษี" Field="WHTTotalVat" DataType="Decimal" TextAlign="Right" AllowEditing="true" Format="{0:n2}">

                                        </ej:Column>
                                    </Columns>
                                    <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True"></EditSettings>
                                    <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>
                                </ej:Grid>

my js

function filtering(e) {
    if (e.text == '')
        e.updateData(e.model.dataSource);
    else {
        var query = new ej.Query().select(['Text', 'Value']);
        query = (e.text !== '') ? query.where('Text', 'contains', e.text, true) : query;
        e.updateData(e.model.dataSource, query);
    }
}

function create() {
    return "<input/>";
}

function readPurchaseWHTCode(args) {
    return value = args.siblings("#" + args.closest(".e-grid").attr("id") + "WHTCode").ejComboBox("model.text");
}

function readPurchaseWHTAmount(args) {
    //return value = args.siblings("#" + args.closest(".e-grid").attr("id") + "WHTAmount").ejNumericTextbox("model.text");
    return value = args.siblings("#" + args.closest(".e-grid").attr("id") + "WHTAmount").ejNumericTextbox("model.value").context.value;
}


function writePurchaseWHTCode(args) {
    $.ajax({
        type: "POST",
        url: "WebService/WHTSetupWS.asmx/Get",
        datatype: "json",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(),
        success: ej.proxy(function (data) {
            $("#MainContent_grdPurchaseWHTIncomeWHTCode").ejComboBox({
                dataSource: data.d.result,
                fields: {
                    value: "Code",
                    text: "CombindedNameTH"
                },
                text: args.rowdata.SourceCode,
                popupHeight: '200px',
                popupWidth: '300px',
                allowFiltering: true,
                filtering: filtering,
                change: purchaseIncomeChange
            });//assign the filtered dataSource obtained from serverSide
        }, this)
    });
}

function writePurchaseWHTAmount(args) {
    $("#MainContent_grdPurchaseWHTIncomeWHTAmount").ejNumericTextbox({
        decimalPlaces: 2,
        width: "100%",
        change: purchaseAmountChange
    }); 
}


function purchaseIncomeChange(args) {
    $.ajax({
        type: "POST",
        url: "WebService/WHTSetupWS.asmx/GetByCode",
        datatype: "json",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ code: args.value }),
        success: ej.proxy(function (data) {
            $("#MainContent_grdPurchaseWHTIncomeWHTPercent").val(data.d.result.WHTPercent + ' %');
            var amount = parseFloat($("#MainContent_grdPurchaseWHTIncomeWHTAmount").val());
            if (amount && amount > 0 && data.d.result.WHTPercent && data.d.result.WHTPercent > 0) {
                $("#MainContent_grdPurchaseWHTIncomeWHTTotalVat").val(parseFloat(amount * data.d.result.WHTPercent / 100).toFixed(2));
            }
        }, this)
    });
}

function purchaseAmountChange(args) {
    var amount = parseFloat($("#MainContent_grdPurchaseWHTIncomeWHTAmount").val());
    var percent = parseFloat($("#MainContent_grdPurchaseWHTIncomeWHTPercent").val().trim().replace("%", ""));
    if (amount && amount > 0 && percent && percent > 0) {
        $("#MainContent_grdPurchaseWHTIncomeWHTTotalVat").val(parseFloat(amount * percent / 100).toFixed(2));
    }
}

























2 Replies

AT Athiwat October 27, 2018 05:54 PM UTC

And my codebehind


protected void grdPurchaseWHTIncome_ServerAddRow(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            try
            {
                List<PurchaseWHTIncome> Lines;
                if (Session["PurchaseWHTLine"] != null)
                {
                    Lines = Session["PurchaseWHTLine"] as List<PurchaseWHTIncome>;
                }
                else
                {
                    Lines = new List<PurchaseWHTIncome>();
                }
                Dictionary<string, object> Record = e.Arguments["data"] as Dictionary<string, object>;
                var WHTCode = (Record.Where(b => b.Key == "WHTCode").FirstOrDefault().Value == null) ? "" : Record.Where(b => b.Key == "WHTCode").FirstOrDefault().Value.ToString();
                var WHTAmount = (Record.Where(b => b.Key == "WHTAmount").FirstOrDefault().Value == null) ? "" : Record.Where(b => b.Key == "WHTAmount").FirstOrDefault().Value.ToString();
                var WHTPercent = (Record.Where(b => b.Key == "WHTPercent").FirstOrDefault().Value == null) ? "" : Record.Where(b => b.Key == "WHTPercent").FirstOrDefault().Value.ToString();
                var WHTTotalVat = (Record.Where(b => b.Key == "WHTTotalVat").FirstOrDefault().Value == null) ? "" : Record.Where(b => b.Key == "WHTTotalVat").FirstOrDefault().Value.ToString();
                PurchaseWHTIncome Line = new PurchaseWHTIncome();
                Line.CompanyCode = Session["CompanyCode"].ToString();
                Line.WHTCode = WHTCode;
                Line.WHTAmount = (WHTAmount == "") ? 0 : Convert.ToDecimal(WHTAmount);
                Line.WHTPercent = (WHTPercent == "") ? 0 : Convert.ToDecimal(WHTPercent.Trim().Replace("%",""));
                Line.WHTTotalVat = (WHTTotalVat == "") ? 0 : Convert.ToDecimal(WHTTotalVat);
                Lines.Add(Line);
                Session["PurchaseWHTLine"] = Lines;
            }
            catch (Exception ex)
            {
            }
            RefreshOptionsPurchaseWHT();
            BindPurchaseWHTLines();
        }




my "record" variable always null


VN Vignesh Natarajan Syncfusion Team October 29, 2018 02:47 PM UTC

Hi Athiwat, 

Thanks for using Syncfusion product. 

Query: ServerAddRow cannot get all column value 
 
From your query, we understand that you are facing issue while adding a new record. We have prepared a sample using your code example and we are not able to reproduce the reported issue at our end. For your convenience we have created the sample based on your code example refer the below link for sample, 


 
  
After referring the sample still facing the issue, please get back to us with following details. 

  1. Share the issue replication procedure.
  2. Share the video demo of the issue (or) if you are facing any error please share the detail.
  3. Share the Essential studio version.
  4. Reproduce the issue in the provided sample and revert us back.

Regards, 
Vignesh Natarajan. 
 


Loader.
Up arrow icon