遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

通过gridview.DataSouce=ds绑定数据时GridViewDeleteEventArgs e 的key为空

代码一:

   gridViewEx.DataSource = ds;
   gridViewEx.DataBind();

代码二:

   protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            //throw new Exception("删除功能已经被屏蔽,如有需要请调整本段代码。");

           //下面Keys集合为空
            int classId = int.Parse(e.Keys["ClassId"].ToString());
            //删除操作

            JsUtil.Alert("记录删除成功!" + classId);
            BindData();
        }
        catch (Exception ex)
        {
            JsUtil.AlertErr(ex.Message);
        }
        finally
        {
            e.Cancel = true;
        }
    }

解决:

int   classId= (int)(gridView.DataKeys[e.RowIndex]["ClassId"]);

参考

http://forums.asp.net/t/1050092.aspx

posted on 2010-05-28 11:18  遗忘海岸  阅读(425)  评论(0编辑  收藏  举报