Migrating editindex after updating GridView

I have a GridView control connected to a data source that allows row editing. I use the standard edit / save / delete buttons that point to the Refresh, Undo, and Edit GridView commands.

I would like to add an additional "Next" button to the line with the save / cancel button. This will work just like the save button, but it will also add an extra line to the grid and put that line into edit mode. To do this, I added code to the UpdatedGridView event , which adds a new record to db, restores the grid, and installs editindex. This seems to work, but the grid does not actually return in edit mode. I deleted the new recording code and simply left the statement to install editindex, but the grid still would not remain in edit mode.

Is it possible to force the grid to remain in edit mode in this scenario? It seems that if you do not set the cancel property GridViewUpdatedEventArgs, the grid will switch to view mode. I do not want to set the cancel property in this case, because I want the GridView to run my data source object to save the record.

If this does not work, it seems that I will need to update the update normally, return to the client, and then send another server request to add the record. I would prefer not to do it this way, I would like to perform the necessary operations in the context of one tour.

Here is what the code looks like (simplified):

protected void Button1_Click(object sender, EventArgs e)
    {
        // Works Fine
        this.sampleDataSource.Insert();
        this.sampleGridView.DataBind();
        this.sampleGridView.EditIndex = this.sampleGridView.Rows.Count - 1;
    }

protected void sampleGridView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        // Grid will display new row, but will not be in edit mode
        this.sampleDataSource.Insert();
        this.sampleGridView.DataBind();
        this.sampleGridView.EditIndex = this.sampleGridView.Rows.Count - 1;
    }
+3
source share
3 answers

, , , , . , GridView , editindex. , , :

protected void sampleGridView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        this.insertNewRow = true;
    }

protected void Page_LoadComplete(object sender, EventArgs e)
    {
        if (this.insertNewRow)
        {
            this.sampleDataSource.Insert();
            this.sampleGridView.DataBind();
            this.sampleGridView.EditIndex = this.sampleGridView.Rows.Count - 1;
        }     
    }
+1

, - ... , . , EditIndex . ( ?), DataBind(), , EditIndex, DataBind().

, EditIndex . DataBind().

0

. : grdProjectsForSubmiting - GridView

grdProjectsForSubmiting.EditIndex = needIndex; // do not forget that the lines are listed from 0, not from 1 !! grdProjectsForSubmiting.DataSource = ProjectsController.SessionTodayEntries;
grdProjectsForSubmiting.DataBind ();

0
source

Source: https://habr.com/ru/post/1732611/


All Articles