代码如下: protected void btdel_Click(object sender, EventArgs e)
    {
        try
        {
            int intCount = this.GridView1.Rows.Count;
            for (int i = 0; i < intCount; i++)
            {
                CheckBox CheckSingle = this.GridView1.Rows[i].Cells[6].FindControl("chk2") as CheckBox;
                if (CheckSingle.Checked)
                {
                    int id = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text.ToString());
                    conn = new OleDbConnection(AccessString + System.Web.HttpContext.Current.Server.MapPath(DataBase));
                    conn.Open();
                    string sqlStr = "delete from UserInfo where id=" + id;
                    OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
                    cmd.ExecuteNonQuery();
                    //this.lbmessage.Text = "删除成功";  
                    Response.Write("删除成功");
                }
            }
            this.DBUserInfo();
        }
        catch
        {
            this.lbmessage.Text = "服务器忙,请一会再试";
        }
        finally
        {
            conn.Close();
        }
    }
 private void DBUserInfo()
    {
        int countpage = Convert.ToInt32(this.lblcurrpage.Text);//当前页
        conn = new OleDbConnection(AccessString + System.Web.HttpContext.Current.Server.MapPath(DataBase));
        conn.Open();
        string sqlText = "select * from UserInfo order by id asc";
        OleDbDataAdapter da = new OleDbDataAdapter(sqlText, conn);
        da.Fill(ds, "text");
        System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables["text"].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 3;
        ps.CurrentPageIndex = countpage - 1;
        this.lbpagecount.Text = Convert.ToString(ps.PageCount);
        if (countpage == 1)
        {
            this.firstpage.Enabled = false;
            this.prepage.Enabled = false;
        }
        else
        {
            this.firstpage.Enabled = true;
            this.prepage.Enabled = true;
        }
        if (countpage == ps.PageCount)
        {
            this.lastpage.Enabled = false;
            this.nextpage.Enabled = false;
        }
        else
        {
            this.lastpage.Enabled = true;
            this.nextpage.Enabled = true;
        }
        this.GridView1.DataSource = ps;
        this.GridView1.DataBind();
        if (this.GridView1.Rows.Count == 0)
        {
            this.panel1.Visible = false;
            this.lbmessage.Text = "没有用户申请注册!";
        }
        else
        {
            this.panel1.Visible = true;
        }
        pagecount = Convert.ToString(ps.PageCount);
        conn.Close();
    }可以成功删除,数据库也更新了,可是GridView中没有马上显示出来,要再刷新一次页面才能更新GridView!怎么回事呀!
删除操作里面,我有调用DBUserInfo()来更新数据的呀!

解决方案 »

  1.   

    OleDbCommand cmd = new OleDbCommand(sqlStr, conn);
                        cmd.ExecuteNonQuery();
    之后加上:
    databind();
      

  2.   

    绑定方法是不是这样用的。
     protected void Page_Load(object sender, EventArgs e)
        {
         if(!IsPostBack)
    {
          BindData();
    }
    }void BindData()         //绑定数据的方法
    {}
      

  3.   

    我看你的代码里有两个gridview吧:ps和gridview1
    你只绑定了gridview1,没绑定ps。
      

  4.   

    只有一个GridView,System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();看ps定义。