We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Selected Row

Thread ID:

Created:

Updated:

Platform:

Replies:

119438 Jun 20,2015 05:09 PM UTC Jun 22,2015 11:13 AM UTC ASP.NET MVC 1
loading
Tags: Grid
lorenza
Asked On June 20, 2015 05:09 PM UTC

Dear All,
I'm a newbie regarding this component.
I need to have the key associated to selected row of a grid and disply it into an input text.
On change of selected row the value will be change.
How can I retrieve this information?
Regards Lorenza


Balaji Marimuthu [Syncfusion]
Replied On June 22, 2015 11:13 AM UTC

Hi lorenza,

Thanks for using Syncfusion Products.

The requested requirement can be achieved by using the client side event RowSelected. Please find a sample and code example as below:
Sample: MvcApplication17

<input type="text" id="txtbox"/>


@(Html.EJ().Grid<MvcApplication17.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowScrolling()

         .AllowPaging()    /*Paging Enabled*/

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

            col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();

            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();

        })

        .ClientSideEvents(eve=> eve.RowSelected("rowselected"))

        )




The RowSelected event will be triggered after a row has been selected and we can get the selected records values by using the method getSelectedRecords.

<script>

    function rowselected(args) {

        var index= this.selectedRowsIndexes; //you can get the selected row index values

        var selectedval = this.getSelectedRecords()[0].OrderID;   //get the selected records values

        $("#txtbox").val(selectedval);

      

    }
</script>


We have displayed the selected records OrderID value to the input text box. Please refer the documentation for more details about rowSelected event and getSelectedRecords method in the following links

RowSelected Event: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#event:rowSelected
getSelectedRecord Method: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#getSelectedRecords

Please let us know if you have any queries.

Regards,
Balaji Marimuthu

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;