Devexprees网格视图点击事件

时间:2015-07-03 07:04:53

标签: javascript asp.net-mvc-4 devexpress

我使用Devexpress控件创建了一个gridview。我想在网格单元格中单击ProductName时在警告框中显示ProductID。 的控制器。

public class HomeController : Controller
    {
        string commString = "";

        public HomeController()
        {
            FWUtility.connString = "Data Source=DEVELOPER1; Initial Catalog=FR8DemoDB; uid=**; pwd=***";
        }
        public ActionResult Index()
        {
            commString = "select ProductID,ProductName from ProductMaster";
            List<ProductMaster> listProductMaster = FWUtility.GetList<ProductMaster>(FWUtility.GetDataTable(commString));
            return View(listProductMaster);
        }
    }
    public class ProductMaster
    {
        public string ProductID { get; set; }
        public string ProductName { get; set; }
    }
}

查看。

function OnCellClick(e) {
        var name = this.dataItem(e.item.index());
        alert(name['ProductID']);
    }
@Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "myGridView";
            settings.CallbackRouteValues = new { Controller = "Home", Action = "Index" };
            settings.Width = 450;
    settings.Columns.Add("ProductName");
            settings.HtmlDataCellPrepared = (sender, e) =>
            {
                e.Cell.Attributes.Add(
                        "onclick", "OnCellClick();"
                );
            };
}).Bind(Model).GetHtml()

项目未定义”这是我点击的错误。我做错了什么?

1 个答案:

答案 0 :(得分:0)

所有DevExpress MVC扩展都公开了许多client-side events,允许您在没有服务器处理的情况下响应最终用户操作。

因此,如果您正在讨论GridView,请使用GridViewClientSideEvents.RowClick事件,如下所示:

function OnRowClick(e) {  ...   }
...
@Html.DevExpress().GridView(
    settings =>
    {
        //...
        settings.ClientSideEvents.RowClick= "OnRowClick";
    }).Bind(Model).GetHtml()