GridView1.UpdateRow(e.RowIndex, true);
会触发
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)你这样写死循环了

解决方案 »

  1.   

    我终于明白为什么会无限递归了!那GridView更新应该怎么写呢?
      

  2.   

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    string KeyValue = GridView1.DataKeys[e.RowIndex].Value.ToString();
    if (KeyValue != "0")
    return; // key value of 0 indicates the insert row System.Web.UI.WebControls.SqlDataSource ds = (System.Web.UI.WebControls.SqlDataSource)this.FindControl(this.GridView1.DataSourceID);
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ds.ConnectionString);
    conn.Open();
    string s = ds.InsertCommand;
    System.Data.SqlClient.SqlCommand c = new System.Data.SqlClient.SqlCommand(s, conn); System.Data.SqlClient.SqlParameter p;
    foreach (System.Collections.DictionaryEntry x in e.NewValues)
    {
    p = new System.Data.SqlClient.SqlParameter("@" + x.Key, x.Value);
    c.Parameters.Add(p);
    }
    p = new System.Data.SqlClient.SqlParameter("@CategoryID", Request.QueryString["ID"]);
    c.Parameters.Add(p);
    c.ExecuteNonQuery();
    }
      

  3.   

    更新不就是得到ID 然后SQL语句