ASP .NET RowUpdating GridView Troubles

后端 未结 3 925
-上瘾入骨i
-上瘾入骨i 2021-01-21 11:46

I\'m having trouble with the RowUpdating Method. My GridView is connected to our local SQL Server, and I\'m trying to update the data. Here is the cod

3条回答
  •  春和景丽
    2021-01-21 12:34

    public void bindGvEdit()
    {
        GridView1.DataSource = obj1.SelectAlltbl();
        GridView1.DataBind();
    }
    
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bindGvEdit();
    }
    
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bindGvEdit();
    }
    
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = GridView1.Rows[e.RowIndex];
        obj1.Id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
        obj1.Name = ((TextBox)row.Cells[1].Controls[1]).Text;
        obj1.Description = ((TextBox)row.Cells[2].Controls[1]).Text;
        obj1.Updatetbl();
        GridView1.EditIndex = -1;
        bindGvEdit();
    }
    

提交回复
热议问题