shanchu

   protected void btn_clear_Click(object sender, EventArgs e)
        {
            //删除某院系的一项分数
            if (GridView1.Rows[0].Cells.Count > 1)
            {
                CheckBox checkBox;
                Session["count"] = "";
                foreach (GridViewRow gridViewRow in GridView1.Rows)
                {
                    checkBox = gridViewRow.FindControl("CheckBox1") as CheckBox;
                    if (checkBox.Checked)
                    {
                        Session["count"] = "check";
                    }
                }
                if (Session["count"].ToString() == "")
                {
                    Response.Write("<script>alert('对不起,你没有选中任何记录,请进行选择!');history.go(-1);</script>");
                }
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                conn.Open();

                int count1 = 0, count2 = 0;//count1为删除成功数,count2为删除未成功的数
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    checkBox = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
                    if (checkBox.Checked)
                    {
                        comm.Parameters.Clear();
                        //comm.CommandText = "delete from T_Score where Score_Faculty_id='" + GridView1.DataKeys[i].Value + "'";
                        comm.CommandText = "delete from T_Score where Score_Faculty_id=@Score_Faculty_id and Score_item_id=@Score_item_id and Score_semester=@Score_semester";
                        comm.Parameters.Add(new SqlParameter("Score_Faculty_id", Convert.ToInt32(GridView1.DataKeys[i].Value)));
                        comm.Parameters.Add(new SqlParameter("Score_item_id", Convert.ToInt64(DDL_evaluationItem.SelectedValue)));
                        comm.Parameters.Add(new SqlParameter("Score_semester", Convert.ToInt64(DDL_semester.SelectedValue)));
                        if (comm.ExecuteNonQuery() == 1)
                        {
                            count1 = count1 + 1;
                        }
                        else
                        {
                            count2 = count2 + 1;
                        }
                    }

                }
                conn.Close();
                if (count2 != 0)
                {
                    Response.Write("<script>alert('" + count2 + "条记录未成功删除!');history.go(-1);</script>");
                }
                else
                {
                    Response.Write("<script>alert('成功删除" + count1 + "条记录!');location.href='SetScore_evaluationItem.aspx';</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('对不起,没有数据可进行删除!');history.go(-1);</script>");
            }

            gridviewDataBind("all");

        }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值