<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <ej:button id="ButtonNormal" runat="server" type="Button" clientsideonclick="Click" size="Normal" text="Click"></ej:button> <ej:grid id="FlatGrid" runat="server" allowpaging="True"> <Columns> <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90"> </ej:Column> <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="90"> </ej:Column> <ej:Column Field="EmployeeID" HeaderText="Employee ID" Width="110"></ej:Column> <ej:Column Field="ShipCity" HeaderText="ShipCity" Width="90" /> </Columns> <PageSettings Template="" ></PageSettings> </ej:grid> <script type="text/javascript"> function Click(element) { var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance"); if (gridObj.getSelectedRecords().length != 0) { var customerID = gridObj.getSelectedRecords()[0]; $.ajax({ url: "/Default.aspx/Data", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ data: customerID }), success: function (data) { alert(data.d); } }) } else alert("No record selected") } [System.Web.Services.WebMethod] public static object Data(Orders data) { //perform operation return "";// return the data |
The getSelectedRecords() method of the Grid returns all the data including the hidden columns. Please find the code example.
<ej:grid id="FlatGrid" runat="server" allowpaging="True"> <Columns> <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90"> </ej:Column> <ej:Column Field="CustomerID" Visible="false" HeaderText="Customer ID" Width="90"> </ej:Column> . . . </ej:grid> <script type="text/javascript"> function Click(element) { var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance"); if (gridObj.getSelectedRecords().length != 0) { var customerID = gridObj.getSelectedRecords()[0]; $.ajax({ url: "/Default.aspx/Data", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ data: customerID }), success: function (data) { alert(data.d); } }) } else alert("No record selected") } [System.Web.Services.WebMethod] public static object Data(Orders data) { //perform operation return "";// return the data |
[aspx] <asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <asp:TextBox id="cus_input" runat="server"></asp:TextBox> <ej:button id="ButtonNormal" runat="server" type="Button" clientsideonclick="Click" size="Normal" text="Click"></ej:button> <ej:grid id="FlatGrid" runat="server" allowpaging="True"> <Columns> . . . </Columns> . . . </ej:grid> <script type="text/javascript"> function Click(element) { var gridObj = $("#<%=FlatGrid.ClientID%>").ejGrid("instance"); if (gridObj.getSelectedRecords().length != 0) { var customerID = gridObj.getSelectedRecords()[0]; customerID.textValue = $('#<%= cus_input.ClientID %>').val(); $.ajax({ url: "/Default.aspx/Data", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ data: customerID }), success: function (data) { alert(data.d); } }) } else alert("No record selected") } </script> public static object Data(Object data) { //perform operation return "";// return the data |
In above sample we create “asp text box” in this sample. We have append the textbox value to getSelectedRecord() array. Please find the code snippet.
var customerID = gridObj.getSelectedRecords()[0]; customerID.textValue = $('#<%= cus_input.ClientID %>').val(); |
Please refers the screen shot:
Regards,
J.Mohammed Farook