遇到个可无奈的问题!
 例如我在  Button1_Click 里写个this.xindian(); 但是代码执行到a就完了!
  并不会再在xindian;方法里去执行xindian; 的代码!  只有页面再刷新时候才会执行!
  下面是我的代码 有点乱!见谅!
public partial class main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string name = Session["name"].ToString();
            this.quanxian();
        }
    }
    public void quanxian()
    {
        string name1 = Session["name"].ToString();
        OleDbConnection olc = DB.CreateDb();
        olc.Open();
        OleDbCommand olm = new OleDbCommand("select * from manager where [username] = '" + name1 + "' ", olc);
        OleDbDataAdapter ola = new OleDbDataAdapter();
        DataSet ds = new DataSet();
        ola.SelectCommand = olm;
        ola.Fill(ds);
        this.GridView1.DataSource = ds.Tables[0];
        this.GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.divyingxiao.Visible = true;
        this.divnews.Visible = false;
        this.xindian();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.divnews.Visible = true;
        this.divyingxiao.Visible = false;
    }
    public void xindian()
    {
        OleDbConnection oln = DB.CreateDb();
        oln.Open();
        OleDbDataAdapter olp = new OleDbDataAdapter();
        OleDbCommand olm = new OleDbCommand("select * from shoplist", oln);
        DataSet dst = new DataSet();
        olp.SelectCommand = olm;
        olp.Fill(dst);
        this.GridView2.DataSource = dst.Tables[0];
        this.GridView2.DataKeyNames = new string[] { "ID" };
        this.GridView2.DataBind();
    }
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int did = Convert.ToInt32(this.GridView2.DataKeys[e.RowIndex].Value.ToString());
        if (DB.shan("delete from shoplist where [ID]=" + did + ""))
        {
            this.xindian();
        }
    }
}
我删除后 页面还会显示被删的, 只有页面再次打时才不会显示!  在线等!

解决方案 »

  1.   


    看完你的代码我也很无奈,写句注释好不好!- -!
     if (DB.shan("delete from shoplist where [ID]=" + did.ToString() + "")) 
            { 
      

  2.   

    Page_Load中加
    Response.Expires = -1;
      

  3.   

    去掉 if (!IsPostBack) 
      

  4.   

    重新绑定了啊!
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) 
        { 
            int did = Convert.ToInt32(this.GridView2.DataKeys[e.RowIndex].Value.ToString()); 
            if (DB.shan("delete from shoplist where [ID]=" + did + "")) 
            { 
                this.xindian();         } 
        } 红色部分
      

  5.   

    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) 

            int did = Convert.ToInt32(this.GridView2.DataKeys[e.RowIndex].Value.ToString()); 
            DB.shan("delete from shoplist where [ID]=" + did + ""); 
            this.xindian(); 

    ----> 如果上面不行,这样:protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) 

        int did = Convert.ToInt32(this.GridView2.DataKeys[e.RowIndex].Value.ToString()); 
        DB.shan("delete from shoplist where [ID]=" + did + "");     Response.Redirect(当前页面);
      

  6.   

    去掉 if 直接绑定
    实在不行  加上这句
    Response.Redirect(this.Page.Request.Url.ToString());
      

  7.   

    你把代码里oln.Open();删掉试验试验,DataAdapter是自动管理连接的,你这句有点多余。
    至于其他的暂时还没看出毛病