1

我想一次获取在 Devexpress MVC GridView 上选择的行。不是在每个点击的项目上。

4

1 回答 1

4

参考: 如何获取所有 GridView 选定的键并将它们传递给控制器

您可以通过ASPxClientGridView.GetSelectedFieldValues方法在客户端收集所有选定的值(例如,键)并将它们传递给:

示例代码片段:

<script type="text/javascript">
    var selectedIDs;
    function OnBeginCallback(s, e) {
        //Pass all selected keys to GridView callback action
        e.customArgs["selectedIDs"] = selectedIDs;
    }
    function OnSelectionChanged(s, e) {
        s.GetSelectedFieldValues("PersonID", GetSelectedFieldValuesCallback);
    }
    function GetSelectedFieldValuesCallback(values) {
        //Capture all selected keys
        selectedIDs = "";
        for (var index = 0; index < values.length; index++) {
            selectedIDs += values[index] + ",";
        }
        if (selectedIDs.length > 0)
            selectedIDs = selectedIDs.substring(0, selectedIDs.length - 1);
    }
    function OnClick(s, e) {
        //Show all selected keys on client side
        alert(selectedIDs);
    }
    function OnSubmitClick(s, e) {
        //Write all selected keys to hidden input. Pass them on post action.
        $("#selectedIDsHF").val(selectedIDs);
    }
</script>

控制器

namespace Sample.Controllers {
    public class HomeController : Controller {
        PersonsList list = new PersonsList();

        [HttpGet]
        public ActionResult Index() {
            return View(list.GetPersons());
        }

        [HttpPost]
        public ActionResult Index(string selectedIDsHF) {
            //Get all selected keys from hidden input
            string _selectedIDs = selectedIDsHF;

            return View(list.GetPersons());
        }

        public ActionResult GridViewEditingPartial() {
            //Get all selected keys from e.customArgs on GridView callback
            string _selectedIDs = Request.Params["selectedIDs"];
            ViewData["_selectedIDs"] = _selectedIDs;

            return PartialView(list.GetPersons());
        }

    }
}

注意:客户端GetSelectedKeysOnPage 方法返回当前页面中显示的选定行的键值。

参考:
GridView - 如何将选定的行作为操作参数
获取 GridView - 如何在控制器的操作中获取选定行的值
如何将选定的 GridView 行放入 Javascript 变量中?
DevExpress MVC GridView - 如何获取单元格单击事件
如何突出显示 DevExpress MVC GridView 页面中的特定行?

于 2014-10-22T04:12:15.333 回答