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. Image for the cookie policy date
close icon

Rows Select

I would like to get values from selected row into textbox.

5 Replies

GV Gowthami V Syncfusion Team June 20, 2016 12:33 PM UTC

Hi Hrvoje, 
 
Thanks for contacting Syncfusion support. 
 
We can get the selected records using “getSelectedRecords” method in client side as follows, 
 
<ej:Grid ID="FlatGrid" runat="server" AllowSorting="True"> 
. . . .  
 
</ej:Grid> 
 
  <script type="text/javascript"> 
        $("#btn").ejButton({ 
            text: "set text value in client side", 
            click: function (args) { 
                var gridObj = $('#<%= FlatGrid.ClientID %>').ejGrid('instance'); 
                var d = gridObj.getSelectedRecords()[0]; 
                $("#txt").val(d.EmployeeID); 
            } 
        }); 
        </script> 
 
Please refer to the below link for more clarification about getSelectedRecords, 
 
 
If you need get the selected row details in RowSelected server side event then refer the below code example, 
 
  <ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowPaging="True" OnServerRowSelected="FlatGrid_ServerRowSelected"> 
.  . . . 
protected void FlatGrid_ServerRowSelected(object sender, GridEventArgs e) 
        { 
            int selectedrowindex = Convert.ToInt32(e.Arguments["rowIndex"]); 
            int id; 
            Dictionary<string, object> data = e.Arguments["data"] as Dictionary<string, object>; 
            foreach (KeyValuePair<string, object> keyval in data) 
            { 
                if (keyval.Key == "EmployeeID") 
                { 
                    id = Convert.ToInt32(keyval.Value); 
                    TextBox1.Text = id.ToString(); 
                } 
            } 
        } 
 
For your convenience we have created a sample and the same can be downloaded from the following link, 
 
 
If we misunderstood your requirement please provide us below details, 
 
1.       Share the detailed explanation of your requirement. 
2.       Screenshot of the requirement. 
 
The provided information will help to analyze the requirement and provide you the response as early as possible. 
 
Regards, 
 
Gowthami V. 



HV Hrvoje Voda June 21, 2016 11:25 AM UTC

This works fine, but I have grid as userControl.
So, I want to get values from Grid.SelectedIndex number...without knowing column name..
Is that possible?


HV Hrvoje Voda June 21, 2016 11:53 AM UTC

I found the solution.
All I need is to raise an event and send data dictionary values.


HV Hrvoje Voda June 21, 2016 12:15 PM UTC

There is only one problem.
After selected row grid is refreshing and return no data.
How can I prevent grid from refresh?
I put update panel but it doesn't work.


GV Gowthami V Syncfusion Team June 22, 2016 10:05 AM UTC

Hi Hrvoje, 
 
Query: After selected row grid is refreshing and return no data. 
 
We are able to reproduce the issue while bind the data to the grid under Page_Load method with checking condition as !IsPostBack as below, 
 
protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) {  
                this.FlatGrid.DataSource = OrderRepository.GetAllRecords().ToList(); 
                this.FlatGrid.DataBind(); 
            } 
             
             
        } 
 
While refreshing the page the !IsPostBack condition get failed and not set the data to the grid. So that only the grid rendered with no data. 
 
If you are facing same issue that data not bound while post back, then we can resolve the issue by set DataSourceCachingMode as “ViewState” or “Sessionwhich is used to cache data on page postback. 
 
Refer to the below code example, 
 
  <ej:Grid ID="FlatGrid" runat="server" DataSourceCachingMode="ViewState"> 
. . . . 
. . . . 
</ej:Grid> 
 
 
To avoid the page refresh while post back then we can render the grid inside update panel.  
 
We have created a sample based on your requirement and the same can be downloaded from the following link, 
 
 
Regards, 
 
Gowthami V. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon