- Home
- Forum
- ASP.NET MVC (Classic)
- Selecting a row on load of Syncfusion grid
Selecting a row on load of Syncfusion grid
Thanks for using Syncfusion Products.
[Grid1.cshtml]
.ClientSideEvents(events=>events.OnLoad("OnLoadGrid1"))
[JavaScript]
<script type="text/javascript">
function OnLoadGrid1(sender, args) {
sender._selectRow=2; // 2 - row index
}
</script>
Please try the above code snippet and let us know if you have any concerns.
Regards,
Bala Murugan A.S
Hi Sivakumar,
Thanks for your update.
We suggest you to pass row index which you want to select from controller to view through response header and select row based on the row index in using _selectRow attribute. Please refer the below code snippets.
[Code snippet]
public ActionResult Index(PagingParams par)
{
if (par.GridID == "Grid1")
{
var data1 = Employee.GetList();
ViewData["GridData1"] = data1;
//Get the index of the record which you want to select
Response.AddHeader("RowIndex", data1.Select((obj, index) => new { obj.EmployeeID, Index = index }).SingleOrDefault(x => x.EmployeeID == 3).Index.ToString());
return data1.GridJSONActions<Employee>();
}
else if (par.GridID == "Grid2")
{
var data1 = Employee.GetList();
ViewData["GridData2"] = data1;
//Get the index of the record which you want to select
//Response.AddHeader("RowIndex", data1.Select((obj, index) => new { obj.EmployeeID, Index = index }).SingleOrDefault(x => x.EmployeeID == 3).Index.ToString());
return data1.GridJSONActions<Employee>();
}
return View();
}
[script]
<script type="text/javascript">
$('#Grid1').ajaxSuccess(function (evt, request, settings) {
var Index = request.getResponseHeader('RowIndex'); //get your data from response header
if (Index != null) {
var gridObj = $find('Grid1');
gridObj._selectRow=Index;
}
});
</script>
Please let us know if you have any concerns.
Regards,
Bala Murugan A.S
- 3 Replies
- 2 Participants
-
SI Sivakumar
- Feb 18, 2013 06:52 AM UTC
- Feb 28, 2013 03:58 AM UTC