问题如下:我在用C#写新闻后台更新程序时,出现了个奇怪的问题:
  首先我简单说明下我的思路:
     我进入后台管理页面,是新闻的一个gridview,点击其中的修改,进入modify页面,该页面的各Textbox的值是从数据库中读取出来的,所以显示的时候是待修改的数据。但是修改完提交以后:
    update语句中,不加where条件时,gridview中所有行都被重置为刚要修改的那一行,而且还是未修改前的数据;加了where条件后,更新就无效了这个问题电脑没有提示任何错误消息,id传值正确,我测试过了
谢谢大侠么,拜谢

解决方案 »

  1.   

    你数据库里面的值改了么?  gridview修改后要从新绑定到页面才能显示出来的
      

  2.   

    修改完没有重新检索数据库绑定到GridView上?
      

  3.   

    修改完 跳回新闻页面,重新绑定一下 ,如果不行的话  你看看modify这个页面修改是否成功
    调试一下看看~!
      

  4.   

    page_load()
    {
    if(!ispostback)
    {
    your code
    }
    }
      

  5.   

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.IO;namespace zjutieyjs.admin
    {
        public partial class modi : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                SqlConnection conn = new SqlConnection("server='(local)';database='news';uid='sa';pwd='sa';");
                conn.Open();
                string str = "select * from news where id='" + Request.QueryString["id"] + "'";
                SqlCommand cmd = new SqlCommand(str, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    TextBox1.Text=rd["Title"].ToString();
                    TextBox2.Text=rd["Time"].ToString();
                    TextBox3.Text=rd["Author"].ToString();
                    DropDownList3.Text=rd["Weather"].ToString();
                    FCKeditor1.Value=rd["Content"].ToString();
                    DropDownList1.Text=rd["Level"].ToString();
                    DropDownList2.Text=rd["Classname"].ToString();
                }
                rd.Close();
                conn.Close();
                    
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    SqlConnection con = new SqlConnection("server='(local)';database='news';uid='sa';pwd='sa';");
                    con.Open();
                    //string strsql = ame) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + FCKeditor1.Value + "','" + DropDownList3.Text + "','" + DropDownList1.Text + "','" + DropDownList2.Text + "')";
                    //string strsql = "UPDATE News SET Title = '" + TextBox1.Text + "',Time = '" + TextBox2.Text + "', Author = '" + TextBox3.Text + "', Content ='" + FCKeditor1.Value + "', Weather = '" + DropDownList3.Text + "', Level = '" + DropDownList1.Text + "',Classname = '" + DropDownList2.Text + "'where ID='" + Request.QueryString["id"] + "'";
                    string strsql = "UPDATE News SET Title = '" + TextBox1.Text + "'where ID='" + Request.QueryString["id"] + "'";
                    SqlCommand cmdd = new SqlCommand(strsql, con);
                    cmdd.ExecuteNonQuery();                StreamReader aw = File.OpenText(Server.MapPath("template.htm"));
                    string template = aw.ReadToEnd();
                    aw.Close();                template = template.Replace("[新闻标题]", TextBox1.Text);
                    template = template.Replace("[发布时间]", TextBox2.Text);
                    template = template.Replace("[新闻作者]", TextBox3.Text);
                    template = template.Replace("[新闻天气]", DropDownList3.Text);
                    template = template.Replace("[新闻内容]", FCKeditor1.Value);                StreamWriter sw = File.CreateText(Server.MapPath("../html/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Second.ToString() + ".htm"));
                    sw.Write(template);
                    sw.Close();                Response.Redirect("manage.aspx");
                    
                }
                catch (Exception ee)
                {
                    Response.Write(ee.ToString());
                }
            }
        }
    }
      

  6.   

    看看 Request.QueryString["id"] 的值是否为空http://www.mybuffet.cn
      

  7.   


    page_load() 

      if(!ispostback)
      { your code } 
    } 顶
      

  8.   


    page_load() 

      if(!ispostback) 
      { your code }