日期:2014-05-18 浏览次数:20388 次
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class show1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request["id"] != null) { SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=sa;Database=web"); con.Open(); SqlDataAdapter ada = new SqlDataAdapter("select * from ERROR where id=" + Request["id"], con); DataSet ds = new DataSet(); ada.Fill(ds, "ERROR"); DataRowView rv = ds.Tables["ERROR"].DefaultView[0]; this.ID.Text = rv["ID"].ToString(); this.AGENT.Text = rv["AGENT"].ToString(); this.PNR.Text = rv["INFORM"].ToString(); this.TextBoxSTATUS.Text = rv["STATUS"].ToString(); } } protected void Button1_Click(object sender, EventArgs e) { Insert(); Response.Write("<script>alert('success!');window.location.href='D.aspx'</script>"); } private void Insert() { SqlConnection con = db.ceratcon(); con.Open(); SqlCommand com = new SqlCommand(); com.Connection = (SqlConnection)con; com.CommandText = "update [ERROR] set AGENT=@AGENT,INFORM=@INFORM,STATUS=@STATUS,DATETIME1=@DATETIME1 where id="+Request["id"]; com.Parameters.Add("@AGENT", SqlDbType.VarChar).Value = this.AGENT.Text; ; com.Parameters.Add("@INFORM", SqlDbType.VarChar).Value = this.PNR.Text; com.Parameters.Add("@STATUS", SqlDbType.VarChar).Value = "DONE"; com.Parameters.Add("@DATETIME1", SqlDbType.DateTime).Value = DateTime.Now; com.ExecuteNonQuery(); con.Close(); } }
if(!Page.IsPostBack) { if (Request["id"] != null) { SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=sa;Database=web"); con.Open(); SqlDataAdapter ada = new SqlDataAdapter("select * from ERROR where id=" + Request["id"], con); DataSet ds = new DataSet(); ada.Fill(ds, "ERROR"); DataRowView rv = ds.Tables["ERROR"].DefaultView[0]; this.ID.Text = rv["ID"].ToString(); this.AGENT.Text = rv["AGENT"].ToString(); this.PNR.Text = rv["INFORM"].ToString(); this.TextBoxSTATUS.Text = rv["STATUS"].ToString(); } }
------解决方案--------------------
textbox的AotuPoatBack为ture
------解决方案--------------------
要将编辑事件与gridview里的编辑命令关联起来,如下代码你可以参考下:
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" OnPageIndexChanged="DataGrid1_PageIndexChanged" OnSortCommand="DataGrid1_SortCommand"
PageSize="3" OnSelectedIndexChanged="Dat