就是  在添加之后不能即时的显示刚添加的数据 ,删除也是,必须要重新生成下项目之后才能看,下面是代码,请各位大大帮忙看看,是不是哪里出错了, protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetDateView("");
            }
        }
        protected void u24_Click(object sender, EventArgs e)
        {
            clear();
        }        protected void GetDateView(string strWhere)
        {
            Ohonly.BLL.News bll = new Ohonly.BLL.News();
            DataSet ds = bll.GetList(5, this.AspNetPager1.CurrentPageIndex, strWhere, "id", "id,title,typeid");
            this.AspNetPager1.PageSize = 5;
            this.AspNetPager1.RecordCount = bll.GetCountId(strWhere);
            this.myGridView.DataSource = ds;
            this.myGridView.DataBind();
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            //  myGridView.DataKeys[e.RowIndex].Value.ToString();
        }
        protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "com")
            {
                string id = e.CommandArgument.ToString();
                BLL.News Bll = new BLL.News();
                DataSet ds = Bll.GetList("id=" + id);
                if (ds != null && ds.Tables[0].Rows.Count != 0)
                {
                    txtTitle1.Text = ds.Tables[0].Rows[0]["Title"].ToString();
                    txtTitle2.Text = ds.Tables[0].Rows[0]["nextTitle"].ToString();
                    droplist.SelectedValue = ds.Tables[0].Rows[0]["Typeid"].ToString();
                    FCKeditor1.Value = ds.Tables[0].Rows[0]["Content"].ToString();
                    textbox1.Text = ds.Tables[0].Rows[0]["id"].ToString();
                }
            }
        }
        protected void myGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            BLL.News Bll = new BLL.News();
            GetDateView("");
        }        protected void myGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            myGridView.EditIndex = -1;
            GetDateView("");        }        protected void myGridView_RowEditing(object sender, GridViewEditEventArgs e)
        {
            myGridView.EditIndex = e.NewEditIndex;
            GetDateView("");        }        protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //if (e.Row.Cells[3].Text.Trim() == "1")
                //{
                //    e.Row.Cells[3].Text = "显示";
                //}
                //else
                //{
                //    e.Row.Cells[3].Text = "不显示";
                //}
                //鼠标经过时,行背景色变
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
                //鼠标移出时,行背景色变
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");                //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                //{
                //    //((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");
                //}
                //}
            }
        }        protected void myGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Common.MessageBox comm = new Common.MessageBox();
            string id = myGridView.DataKeys[e.RowIndex].Value.ToString();
            BLL.News Bll = new BLL.News();
            Bll.Delete(int.Parse(id));
            comm.ShowAndRedirect(this, "删除成功","../Backend/EditNews.aspx");
            GetDateView("");
        }        protected void AspNetPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            GetDateView("");
        }        protected void btnSub_Click(object sender, EventArgs e)
        {
            BLL.News bll = new BLL.News();
            Ohonly.Model.News model = new Ohonly.Model.News();
            Common.MessageBox comm = new Common.MessageBox();
            if (this.textbox1.Text == null || this.textbox1.Text == "")
            {
                model.TypeID = Convert.ToInt32(droplist.SelectedValue.Trim());
                model.Title = this.txtTitle1.Text.Trim();
                model.nextTitle = this.txtTitle2.Text.Trim();
                model.IsNew = 0;
                model.Da_Create = DateTime.Now;
                model.Content = this.FCKeditor1.Value;                int a = bll.Add(model);
                if (a > 0)
                {
                    comm.Show(this,"添加成功");
                    GetDateView("");
                }
                else
                {
                    comm.Show(this, "添加失败");
                    GetDateView("");
                }
            }
            else
            {
                model.ID = Convert.ToInt32(this.textbox1.Text);
                model.Title = this.txtTitle1.Text.Trim();
                model.nextTitle = this.txtTitle2.Text.Trim();
                model.IsNew = 0;
                model.TypeID = Convert.ToInt32(this.droplist.SelectedValue);
                model.Content = this.FCKeditor1.Value;
                bool a = bll.Update(model);
                if (a)
                {
                    
                    comm.Show(this, "修改成功");
                    GetDateView("");
                    
                }
                else
                {
                    comm.Show(this, "修改失败");
                    GetDateView("");
                }
            }
        }
        public void clear()
        {
            this.txtTitle1.Text = "";
            this.txtTitle2.Text = "";
            this.FCKeditor1.Value = "";
            this.textbox1.Text = "";
        }

解决方案 »

  1.   

    设断点试一下在你执行完你要的操作之后,重新databind()了吗?
      

  2.   

    我们这样很难看出问题的,
    你把GetList(5, this.AspNetPager1.CurrentPageIndex, strWhere, "id", "id,title,typeid");
    和Add函数贴出来
    还有重复的哪行是你添加的哪行吗??
      

  3.   

    一语惊醒梦中人啊,我的bll里,加了个缓存,大爷的,我给忘记了
    谢两位捧场,分给两位平分了哈