asp.net GridView增加删除功能

时间:2022-12-28 08:20:15

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        bool b = new olecado().deletecategory(id);
        if (b)
        {
            string bianm = Request.QueryString["bm"].ToString().Trim();
            rebindby(bianm);
        }

}

/// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool deletecategory(string id)
        {
            bool flag = false;
            string cmdtext = "delete from ry where id=@id";
            OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@id", id) };
            int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }