user3208483
user3208483

Reputation: 397

ASP.NET MVC ClientSide Events

I am trying to learn MVC, coming from a .NET background. I have a index page with a devexpress gridview control and am trying to add a focusedrowchanges event. My index page consists of just the following

<main style="width:100%">
    @Html.Action("GridViewPartial")
</main>

My Gridviewpartial is as follows

@{
    var grid = Html.DevExpress().GridView(settings =>
    {
    settings.Name = "GridView";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };

    settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "GridViewPartialAddNew" };
    settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Home", Action = "GridViewPartialUpdate" };
    settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Home", Action = "GridViewPartialDelete" };
    settings.ClientSideEvents.FocusedRowChanged = "OnRowSelect";
    //settings.ClientSideEvents.FocusedRowChanged = "function(s, e) {alert('The button has been clicked');}";


    settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
    settings.SettingsBehavior.ConfirmDelete = true;

    settings.CommandColumn.Visible = false;
    settings.CommandColumn.ShowNewButton = false;
    settings.CommandColumn.ShowDeleteButton = false;
    settings.CommandColumn.ShowEditButton = false;

    settings.KeyFieldName = "id";

    settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

    settings.SettingsAdaptivity.AdaptivityMode = GridViewAdaptivityMode.Off;
    settings.SettingsAdaptivity.AdaptiveColumnPosition = GridViewAdaptiveColumnPosition.Left;
    settings.SettingsAdaptivity.AdaptiveDetailColumnCount = 1;
    settings.SettingsAdaptivity.AllowOnlyOneAdaptiveDetailExpanded = false;
    settings.SettingsAdaptivity.HideDataCellsAtWindowInnerWidth = 0;

    settings.Columns.Add("reference");
    settings.Columns.Add("name");
    settings.Columns.Add("description");

});
if (ViewData["EditError"] != null)
{
    grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()

As you can see, I have added a focusedrowchanges event and tried 2 different ways of using it. I am currently trying to get it to use a javascript function.

<script type="text/javascript">
    function OnRowSelect(s, e) {
        alert('test');
        }
</script>

It doesnt seem to enter the function when I change focused rows on the grid and I dont know why this is. I have also tried putting a breakpoint in the function and this is never hit. Can somebody explain how I should do this correctly?

Upvotes: 0

Views: 867

Answers (1)

Ronald
Ronald

Reputation: 26

Both your methods will work (tried this on one of my own projects). You're just missing one setting: settings.SettingsBehavior.AllowFocusedRow = true;

See the DevExpress demo also demonstrating the same.

Upvotes: 1

Related Questions