添加完新记录后用Response.Redirect和window.location跳转去显示,都不显示最新记录是怎么回事?asp.net2.0+repeater做的。

解决方案 »

  1.   

    add.aspx的代码: protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string varname = username.Text.Trim().ToString();
            string varneirong = neirong.Text.Trim().ToString();
            if (varname != "" && varneirong != "")
            {
                //连接数据库
                OleDbConnection myconn = Class1.getconn();
                myconn.Open();            varneirong = HtmlEncode(varneirong);            //编号自动累加================
                OleDbCommand cmm0 = new OleDbCommand("select bianhao from biao order by bianhao desc", myconn);
                OleDbDataReader dr = cmm0.ExecuteReader();           
                
                int mybianhao = 0;
                if (dr.Read())
                {
                    mybianhao = Convert.ToInt16(dr["bianhao"]) + 1;               
                }
                else
                {
                    mybianhao = 1001;
                }
                string varbianhao = mybianhao.ToString();           
                //招待执行插入操作
                   OleDbCommand cmm = new OleDbCommand("insert into biao(username,bianhao,neirong) values('" + varname + "','" + varbianhao + "','" + varneirong + "')", myconn);
                   cmm.ExecuteNonQuery();             Response.Redirect("edit.aspx");
                             //==========================           
            }
            else
            {
                Response.Write("请把信息填写完整!");
            }
        }
    edit.aspx的代码: protected void Page_Load(object sender, EventArgs e)
        {
                    
                if (!IsPostBack)
                {
                    mybind();
                }        
            
        }    public void mybind()
        {
          
            OleDbConnection myconn = Class1.getconn();
            myconn.Open();        OleDbCommand cmm = new OleDbCommand("select * from biao order by id desc", myconn);
            OleDbDataAdapter da = new OleDbDataAdapter(cmm);
            DataSet ds = new DataSet();        //统计条数
            OleDbCommand cmm1 = new OleDbCommand("select count(*)  from biao", myconn);
            string x = cmm1.ExecuteScalar().ToString();
            mynum.Text = x;
            //        da.Fill(ds, "myliuyan");        Repeater1.DataSource = ds.Tables["myliuyan"];
            Repeater1.DataBind();        OleDbCommand cmm2 = new OleDbCommand("select * from pinglun", myconn);
            OleDbDataAdapter da2 = new OleDbDataAdapter(cmm2);//从留言表中查询记录
            da2.Fill(ds, "myhuifu");
            
            ds.Relations.Add("mybiao", ds.Tables["myliuyan"].Columns["bianhao"], ds.Tables["myhuifu"].Columns["bianhao"]);        Page.DataBind();        //分页显示******************************************************
            PagedDataSource ps = new PagedDataSource();
            int CurrentPage = Convert.ToInt32(pagenow.Text);
            ps.DataSource = ds.Tables["myliuyan"].DefaultView;
            ps.AllowPaging = true; //是否可以分页
            ps.PageSize = 5; //每页几条记录
            ps.CurrentPageIndex = CurrentPage - 1; //取得当前页的页码
            frontpage.Enabled = true;
            firstpage.Enabled = true;
            nextpage.Enabled = true;
            lastpage.Enabled = true;
            if (CurrentPage == 1)
            {
                firstpage.Enabled = false;//不显示第一页按钮
                frontpage.Enabled = false;//不显示上一页按钮
            }
            if (CurrentPage == ps.PageCount)
            {
                nextpage.Enabled = false;//不显示下一页
                lastpage.Enabled = false;//不显示最后一页        }
            totalpage.Text = Convert.ToString(ps.PageCount);
            Repeater1.DataSource = ps;        
            Repeater1.DataBind();
            //*****************************************************************
        }    //分页链接*************************************************************s    //首页
        protected void firstpage_Click(object sender, EventArgs e)
        {
            pagenow.Text = "1";
            mybind();
        }
        //下一页
        protected void nextpage_Click(object sender, EventArgs e)
        {
            pagenow.Text = Convert.ToString(Convert.ToInt32(pagenow.Text) + 1);
            mybind();
        }
        //上一页
        protected void frontpage_Click(object sender, EventArgs e)
        {
            pagenow.Text = Convert.ToString(Convert.ToInt32(pagenow.Text) - 1);
            mybind();
        }
        //尾页
        protected void lastpage_Click(object sender, EventArgs e)
        {
            pagenow.Text = totalpage.Text;
            mybind();
        }
        
      

  2.   

    要是数据添加成功了
    window.location ,window.open有一个是绝对可能成功的,具体的忘了