Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView行更新在回发后返回旧值_C#_Asp.net_Gridview - Fatal编程技术网

C# GridView行更新在回发后返回旧值

C# GridView行更新在回发后返回旧值,c#,asp.net,gridview,C#,Asp.net,Gridview,我的GridView有问题。当我试图编辑我的GridView时,我只得到旧值作为回报 以下是RowUpdate事件: protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; TextBox nVorname = (TextBox)row.FindControl("new

我的GridView有问题。当我试图编辑我的GridView时,我只得到旧值作为回报

以下是RowUpdate事件:

protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
    TextBox nVorname = (TextBox)row.FindControl("newVorname");
    TextBox nNachname = (TextBox)row.FindControl("newNachname");
    TextBox nTelnr = (TextBox)row.FindControl("newTelnr");
    TextBox nEmail = (TextBox)row.FindControl("newEmail");
    HiddenField tid = (HiddenField)row.FindControl("id");

    grid.EditIndex = -1;

    SqlConnection sqlConn = new SqlConnection("server=localhost;Integrated Security=true;database=Telefonbuch;");
    sqlConn.Open();
    SqlCommand cmd = new SqlCommand("update dasOertliche set vorname= @vorname, nachname=@nachname, telefonnr =@telnr, email =@email where id = @id", sqlConn);
    cmd.Parameters.Add("@vorname", SqlDbType.VarChar);
    cmd.Parameters["@vorname"].Value = nVorname;
    cmd.Parameters.Add("@nachname", SqlDbType.VarChar);
    cmd.Parameters["@nachname"].Value = nNachname.Text;
    cmd.Parameters.Add("@email", SqlDbType.VarChar);
    cmd.Parameters["@email"].Value = nEmail.Text;
    cmd.Parameters.Add("@telnr", SqlDbType.VarChar);
    cmd.Parameters["@telnr"].Value = nTelnr.Text;
    cmd.Parameters.Add("@id", SqlDbType.Int);
    cmd.Parameters["@id"].Value = tid.Value;

    cmd.ExecuteNonQuery();
    sqlConn.Close();
    bind();
}
.aspx中的TemplateField:

 <Columns>
    <asp:TemplateField HeaderText = "Vorname">
    <ItemTemplate>    <%#Eval ("vorname") %></ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="newVorname" runat="server" Text='<%#Eval ("vorname") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
   </columns>
我的绑定():


最后需要调用
GridView1.DataBind()

最后需要调用
GridView1.DataBind()

在Pageload上,将绑定网格代码置于以下条件

 protected void Page_Load(object sender, EventArgs e)
        {
             if (!Page.IsPostBack)
               {
                  bind();
               }
        }

在Pageload上,将绑定网格代码置于以下条件

 protected void Page_Load(object sender, EventArgs e)
        {
             if (!Page.IsPostBack)
               {
                  bind();
               }
        }
这是错误的

应该是:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        bind();
    }
}
这是错误的

应该是:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        bind();
    }
}

到底在哪里?我在比赛的最后一部分做。最后在哪里?我在行更新的最后一部分进行了更新。我已经更新了答案,请像这样尝试删除绑定();它位于if(!Page.IsPostBack)行上方,并且只保留bind();我已经更新了答案,请像这样尝试删除绑定();它位于if(!Page.IsPostBack)行上方,并且只保留bind();它处于if状态。
protected void Page_Load(object sender, EventArgs e)
{
    bind();
    if (!Page.IsPostBack)
    {
        bind();
    }
}
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        bind();
    }
}