title: ASP.NET GridView Multiple Edit Rows At Same Time
body: <p>In ASP.NET 4.0 GridView, is it possible to have multiple rows in edit mode at the same time?</p>
  
  <p>I'm controlling the rows with edit mode in a property:</p>
  
  <pre><code>Private Property Editing As List(Of Integer)
     Get
         If ViewState("Editing") Is Nothing Then ViewState("Editing") = New List(Of Integer)
         Return CType(ViewState("Editing"), List(Of Integer))
     End Get
     Set(value As List(Of Integer))
         ViewState("Editing") = value
     End Set
  End Property
  </code></pre>
  
  <p>Populating it when the user clicks on edit button:</p>
  
  <pre><code>Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
      If e.CommandName = "Edit" Then
          Dim row = CType(CType(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
          Editing.Add(row.RowIndex)
      End If
  End Sub
  </code></pre>
  
  <p>And changing the RowState property manually in the RowDataBound event:</p>
  
  <pre><code>Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
      If e.Row.RowType = DataControlRowType.DataRow Then
          If Editing.Contains(e.Row.RowIndex) Then
              Then e.Row.RowState = DataControlRowState.Edit
          End If
      End If
  End Sub
  </code></pre>
  
  <p>But it's not working, the rows is being rendered in the normal state... any ideias?</p>
  
  <hr>
  
  <p>EDIT 2: PROPERTY</p>
  
  <p>MultipleEditGridView.vb:</p>
  
  <pre><code>Namespace ClubeCheckIn.UI
  
          Public Class MultipleEditGridView
              Inherits GridView
  
              Protected Property IsRowInEditMode(rowIndex As Int32) As Boolean
                  Get
                      If ViewState("GridRowEditIndices") Is Nothing Then
                          Return False
                      Else
                          Dim indices = DirectCast(ViewState("GridRowEditIndices"), List(Of Int32))
                          Return indices.Contains(rowIndex)
                      End If
                  End Get
                  Set(value As Boolean)
                      If ViewState("GridRowEditIndices") Is Nothing Then
                          ViewState("GridRowEditIndices") = New List(Of Int32)
                      End If
                      Dim indices = DirectCast(ViewState("GridRowEditIndices"), List(Of Int32))
                      indices.Remove(rowIndex)
                      indices.Add(rowIndex)
                  End Set
              End Property
  
          End Class
  
      End Namespace
  </code></pre>
  
  <p>web.config:</p>
  
  <pre><code>&lt;controls&gt;
      &lt;add tagPrefix="clube" namespace="ClubeCheckIn.UI" /&gt;
  &lt;/controls&gt;
  </code></pre>
  
  <p>ASPX:</p>
  
  <pre><code>&lt;clube:MultipleEditGridView ID="GridView1" runat="server"&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:TextBox ID="txtEdit" runat="server" Visible="&lt;%# IsRowInEditMode(Container.DataItemIndex) %&gt;" /&gt;
              &lt;/ItemTemplate&gt;
      &lt;/Columns&gt;
  &lt;/clube:MultipleEditGridView&gt;
  </code></pre>
  
  <p>ERROR:</p>
  
  <p>Error: BC30451: 'IsRowInEditMode' is not declared. It can be inacessible due to the protection level</p>