• 三、gridView增删改查


    1. 新增或修改一条数据

      1.1 添加 新增或修改按钮

     1     <div style=" 120px; float: right; padding-top: 3px">
     2         @Html.DevExpress().Button(settings =>
     3         {
     4             settings.Name = "btnUpdate";
     5             settings.ControlStyle.CssClass = "button";
     6             settings.Text = "修改";
     7             settings.UseSubmitBehavior = true;
     8             settings.ClientSideEvents.Click = "updateData";
     9         }).GetHtml()
    10     </div>
    11 
    12     <div style=" 120px; float: right; padding-top: 3px">
    13         @Html.DevExpress().Button(settings =>
    14         {
    15             settings.Name = "btnAdd";
    16             settings.ControlStyle.CssClass = "button";
    17             settings.Text = "新增";
    18             settings.UseSubmitBehavior = true;
    19             settings.ClientSideEvents.Click = "addData";
    20         }).GetHtml()
    21     </div>
    btnAddorUpdate

      1.2 新增或修改按钮JS

     1     function updateData(s, e) {
     2         GridView.GetSelectedFieldValues("DocumentId", GetSelectedFieldValuesCallbackForModify);
     3     }
     4 
     5     function GetSelectedFieldValuesCallbackForModify(values) {
     6         if (values.length != 1) {
     7             alert("请选择一个修改项");
     8         } else {
     9             $.ajax({
    10                 type: "GET",
    11                 url: '@Url.Action("UpdateOrAdd", "Home")',
    12                 data: { "id": values[0] },
    13                 datatype: "html",
    14                 ansy: false,
    15                 cache: false,
    16                 success: function (data) {
    17                     $('#content').html(data);
    18                     $("#DocumentId").val(values[0]);
    19                     addorUpdate.Show();
    20                 },
    21                 error: function () {
    22                     alert("处理失败!");
    23                 }
    24             });
    25         }
    26     }
    27 
    28     function addData(s, e) {
    29         $.ajax({
    30             type: "GET",
    31             url: '@Url.Action("UpdateOrAdd", "Home")',
    32             data: '',
    33             datatype: "html",
    34             ansy: false,
    35             cache: false,
    36             success: function (data) {
    37                 $('#content').html(data);
    38                 addorUpdate.Show();
    39             },
    40             error: function () {
    41                 alert("处理失败!");
    42             }
    43         });
    44     }
    View Code

      1.3 新增或修改Controller

  • 相关阅读:
    机试指南
    Python 切片与深拷贝
    list去重,求差集,保持顺序不变
    python--coding
    python --cookbook
    H5py文件
    面向对象
    企业微信和微信公众号获取wx.config的安卓和ios的区别----踩坑
    vue+vant实现上拉加载下拉刷新(访问后台逻辑)
    vue实现前端跨域问题
  • 原文地址:https://www.cnblogs.com/dujinyang/p/6705011.html
Copyright © 2020-2023  润新知