Sending Value of ASP.Net textbox to Jqgrid save event

纵然是瞬间 提交于 2019-12-25 18:28:03

问题


I have got an asp.net form, with a jqgrid on it. The user can enter an account number on a main form, and then enter some data onto a jqgrid.

At the point the user saves the row in the grid, i would also like to pass the account number across from the form to the save proc, as we use this to work out some discount info for the lines in the grid.

I'm not sure how at the point of saving to pass this information accross?

UPDATE

I'm using json as my datatype, using inline editing and using editurl to post the grid to a web service that deals with saving it to a back end database.

UPDATE 2 - Solution

This is the code i have used to pass the value of a text box to along with the normal post data

jQuery(grid).jqGrid('inlineNav', "#pager", { edit: false, add: true, del: false, search: false,

                //add the extra params to the post call
                addParams: {
                    useDefValues: true,
                    addRowParams: {
                        keys: true,
                        aftersavefunc: reloadGrid,
                        extraparam: { accNo: getAccNumber, colourName: getColName }
                    }
                },
                editParams: {
                    keys: true,
                    aftersavefunc: reloadGrid,
                    extraparam: { accNo: getAccNumber, colourName: getColName }
                }
            });

This function gets the value of the asp.net text box

//get the value of the account number field
            getAccNumber = function () {
                return $("#<%= txtAccNo.ClientID %>").val();
            };

回答1:


You can use extraparam option of editRow:

onSelectRow: function (id) {
    ...
    $(this).jqGrid('editRow', id, {
        keys: true,
        url: "yourServerUrl",
        extraparam: {
            accountNumber: function () {
                return $("#accountNr").val();
            }
        }
    });
    ....
}

Additional parameter accountNumber with the current value from the input field with id="accountNr" will be sent additionally to the standard data.

You can see here the corresponding demo. Because no URL are exist under http://www.ok-soft-gmbh.com/jqGrid/myServerUrl one will get an error, but one can easy verify in the Fiddler, Firebug or in Developer Tools of IE or Chrome that additional parameter accountNumber will be really send to the server.

In case of ASP.NET code you could be needed to use the syntax like "<%=accountNumber.ClientID%>" to get id of the corresponding input field of the form.

One can use alternatively inlineData option of jqGrid with properties defined as methods. The idea here is the same as described here for postData. In the answer you will find an example where inlineData are used.



来源:https://stackoverflow.com/questions/13033481/sending-value-of-asp-net-textbox-to-jqgrid-save-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!