- Home
- Forum
- ASP.NET Web Forms
- Selected row
Selected row
Thanks for contacting Syncfusion support.
While using button sever click event, we can get the button model in server side can’t get the grid model. So we need to pass the selected records before trigger the server side click event. We suggest you to use Ajax method in clientsideonclick event to get the selected records in server side.
Please refer to the code example and sample,
|
<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 |
Sample: http://www.syncfusion.com/downloads/support/forum/121627/ze/Sample_121627680167393
Refer to the online help documentation for getSelectedRecords(),
Document: http://help.syncfusion.com/js/api/ejgrid#methods:getselectedrecords
Screen shot to get the selected records in server side.
Regards,
Sellappandi R
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 |
For your convenience we have prepared a sample that can be downloaded from the following link:
Sample: http://www.syncfusion.com/downloads/support/directtrac/149498/ze/Sample1827275800
Refer to the screen shot to get the selected records in server side:
Please let us know if you have any queries.
Regards,
J.Mohammed Farook
Based on your request we have created a sample and it can be downloaded from the following link:
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample2109893463.zip
Please find the code snippet.
| [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
- 5 Replies
- 3 Participants
-
MS Manuel Santos
- Jan 10, 2016 07:09 PM UTC
- Jan 18, 2016 01:46 PM UTC