欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » ASP.Net » 正文

热门阅读

AspxGridview提示不支持所指定的方法的解决方法

创建时间:2012年07月02日 11:33  阅读次数:(9807)
分享到:
今天在使用AspxGridView自定义的update按钮事件的时候,总是报出"不支持所指定的方法"的错误,英文错误是"Specified method is not supported"。因为以前都没有用过AspxGridView自带的update,delete,addnew等方法,所以该问题一直都没有发现。

使用场景是这样的,使用AspxGridView自带的编辑数据功能,点击一个自定义按钮调用StartEdit()方法或AspxGridView自带的Edit按钮,出来了数据编辑窗口,编辑完数据后点击Update,就报出了不"支持所指定的方法"的错误

穿插一下,如果想要把按钮名"update","cancel"改成中文的,可以做如下设置:
<SettingsText CommandCancel="取消" CommandUpdate="确定" />

继续回来,找了以前一个使用DataSourceID绑定AspxGridView的示例来看,发现在用DataSourceID绑定AspxGridView的时候,定义了DeleteMethod,InsertMethod,UpdateMethod三个方法,那我们使用自定义的方法是不是也必须同时定义这三个方法呢,经测试后确实如此。

代码如下:
grid.RowUpdating += new DevExpress.Web.Data.ASPxDataUpdatingEventHandler(grid_RowUpdating);
grid.RowInserting += new DevExpress.Web.Data.ASPxDataInsertingEventHandler(grid_RowInserting);
grid.RowDeleting += new DevExpress.Web.Data.ASPxDataDeletingEventHandler(grid_RowDeleting);

也可以在前台定义:
 <dxwgv:AspxGridView ID="grid" runat="server" KeyFieldName="ID" OnRowDeleting="grid_RowDeleting" OnRowInserting="grid_RowInserting" OnRowUpdating="grid_RowUpdating">

grid_RowUpdating,grid_RowInserting,grid_RowDeleting三个方法如下:
void Grid_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
    e.Cancel = true;
}

void Grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
    e.Cancel = true;
}

void Grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
    BLL.Target bll = new SDIR.BLL.Target();
    decimal t_value = 0;
    string t_type = "months";
    switch (ReportType)
    {
        case ReportType.Months:
            {
                t_type = "months";
                break;
            }
    }

    for (int i = 0; i < DateCol_List.Count; i++)
    {
        if (decimal.TryParse(e.NewValues[DateCol_List[i]].ToString(), out t_value))
        {
            bll.Update(FormID, Convert.ToDateTime(DateCol_List[i]), t_value, t_type);
        }
    }
    e.Cancel = true;
    (sender as AspxGridView).CancelEdit();

    if (base.Events[_o_grid_updateed] != null)
    {
        EventHandler grid_updateed = base.Events[_o_grid_updateed] as EventHandler;
        grid_updateed(sender, EventArgs.Empty);
    }
}


上面Grid_RowUpdating方法中的代码不用理会,是我自己的调试代码,但需要注意的是,在三个方法中,代码e.Cancel = true一定不能少,如果没有这句代码,还是会报"不支持所指定的方法"的错误。

总结,AspxGridView出现"不支持所指定的方法"的错误时,大家应该确认以下四点。
1、AspxGridView已设置了主键,即KeyFieldName属性
2、AspxGridView已定义了事件 OnRowDeleting, OnRowInserting, OnRowUpdating
3、后台有对 OnRowDeleting, OnRowInserting, OnRowUpdating 事件的处理
4、OnRowDeleting, OnRowInserting, OnRowUpdating方法中都包含e.Cancel = true代码。 table.Rows.AddAt(0, tr);

  
来源:.net学习网
说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
【编辑:Wyf

打赏

取消

感谢您的支持,我会做的更好!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论1条
  • #1楼  评论人:学习者  评论时间:2013-8-16 14:59:27
  • 非常感谢!很实用!
发表评论:
留言人:
内  容:
请输入问题 11+93=? 的结果(结果是:104)
结  果: