Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you want to put your GridView in Edit mode programmatically,set the <code>EditIndex</code> property to the appropriate row. </p> <pre><code>protected void Button1_Click(object sender, EventArgs e) { GridView1.EditIndex = 1; } </code></pre> <p><strong>NOTE:</strong> </p> <p>1.) In case you are binding gridview from markup, using DataSourceControls such as <code>SqlDataSource</code>, No Need to call the <code>GridView.Bind()</code>. </p> <p>2.) If you are binding GridView at runtime using the DataSource property, you should rebind your gridView.</p> <p>In <strong>your Question</strong>: <code>surprisingly, its just changing row mode, where edit button is pressed.</code>, since you are clicking the <code>Edit</code> button, handle the <code>OnRowEditing</code> event and set the <code>NewEditIndex</code> property, if you want some other row to be in edit mode::</p> <pre><code>&lt;asp:GridView ID="CustomersGrIdView" OnRowEditing="CustomersGridView_Editing" OnRowCommand="CustomersGridView_RowCommand" .... /&gt; protected void CustomersGridView_Editing(object sender, GridViewEditEventArgs e) { e.NewEditIndex = 3; // Tested in VS 2010, Framework 4 } </code></pre> <p><em><strong>Now regardless of any row's <code>Edit</code> button clicked, you will always find, the 3rd row in Edit mode.</em></strong> [ Row Numbering starts from 0 ]</p> <p>This is what <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.editindex.aspx" rel="nofollow"><strong>MSDN</strong></a> has to say about <code>EditIndex</code> property. <strong>Most of the time, we use the Option C</strong>.</p> <p>This property is typically used only in the following scenarios, which involve handlers for specific events:</p> <pre><code>a. You want the GridView control to open in edit mode for a specific row the first time that the page is displayed. To do this, you can set the EditIndex property in the handler for the Load event of the Page class or of the GridView control. b. You want to know which row was edited after the row was updated. To do this, you can retrieve the row index from the EditIndex property in the RowUpdated event handler. c. You are binding the GridView control to a data source by setting the DataSource property programmatically. In this case you must set the EditIndex property in the RowEditing and RowCancelingEdit event handlers. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload