为什么更新始终获取第一行

      protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {       
        int id = Convert.ToInt32(GridView2.Rows[e.AffectedRows].Cells[0].Text);    
        string bname = GridView2.Rows[e.AffectedRows].Cells[1].Text;
        string bauthor = GridView2.Rows[e.AffectedRows].Cells[2].Text;
        string bprice = GridView2.Rows[e.AffectedRows].Cells[3].Text;
        string url="Update.aspx?bname="+Server.UrlEncode(bname)+"&bauthor="+Server.UrlEncode(bauthor)+"&bprice="+Server.UrlEncode(bprice)+"&bid="+Server.UrlEncode(id.ToString());
        Response.Redirect(url);   
    }

e.AffectedRows,这个不是更新行的下标。

参考:http://www.cnblogs.com/SkySoot/archive/2012/08/10/2632153.html

protected void detailsEditing_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
    if (e.AffectedRows == 0)
    {
        e.KeepInEditMode = true; // 保持在编辑模式
        detailsEditing.DataBind(); // 重新绑定最新的数据

        // 把先前更新失败的用户编辑的值重新放回文本框
        // 这些原本要保存的值被放置在 e.NewValues 集合中
        TextBox txt;
        txt = detailsEditing.Rows[1].Cells[1].Controls[0] as TextBox;
        txt.Text = e.NewValues["CompanyName"].ToString(); 
        txt = detailsEditing.Rows[2].Cells[1].Controls[0] as TextBox;
        txt.Text = e.NewValues["Phone"].ToString();
        errorPanel.Visible = true;
    }
} 

另外提醒lz如果问题解决请及时采纳。