Getting the index of the last row inserted in a GridView
<p>How do I get the row index of the last row inserted in a GridView considering the user may have custom ordering in the grid (I can't use the last row).</p>

<pre><code>    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        SqlDataSourceCompleteWidget.Insert();
        GridViewCompleteWidget.DataBind();
        GridViewCompleteWidget.EditIndex = ??????;
    }
</code></pre>

<p>I want to put the row into edit mode immediately after the insert occurs.</p>

<p>UPDATE</p>

<pre><code>    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        //SqlDataSourceCompleteWidget.InsertParameters.Add("EFFECTIVE_DATE", Calendar1.SelectedDate.ToString("yyyy-MM-dd"));
        SqlDataSourceCompleteWidget.InsertParameters[0].DefaultValue = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
        SqlDataSourceCompleteWidget.Insert();
        GridViewCompleteWidget.DataBind();
        GridViewCompleteWidget.EditIndex = 1;
    }

    private int mostRecentRowIndex = -1;
    protected void GridViewCompleteWidget_RowCreated(object sender, GridViewRowEventArgs e)
    {
        mostRecentRowIndex = e.Row.RowIndex;

        //GridViewCompleteWidget.EditIndex = e.Row.RowIndex;
    }
</code></pre>
