title: GridView RowCommand Event and Saving Text
body: <p>I have a GridView set up:</p>
  
  <pre><code>&lt;asp:GridView id="GridView1" Runat="server" AutoGenerateColumns="False" OnRowCommand = "GridView1_RowCommand" EnableViewState="true"&gt;
     &lt;Columns&gt;
         &lt;asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center"&gt; 
              &lt;ItemTemplate&gt;&lt;asp:Button runat="server" ID="Delete" ImageUrl="~/images/Close.gif" CommandName="DeleteRow" CommandArgument="&lt;%# CType(Container,GridViewRow).RowIndex %&gt;"/&gt;&lt;/ItemTemplate&gt;&lt;/asp:TemplateField&gt;
  
         &lt;asp:TemplateField HeaderText="Comment" ItemStyle-Width="175px"&gt;
              &lt;ItemTemplate&gt;&lt;textarea class="raTextBox" id="txtItemComment" rows="4" cols="30"&gt;&lt;/textarea&gt;&lt;/ItemTemplate&gt;&lt;/asp:TemplateField&gt; 
     &lt;/Columns&gt;   
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>The RowCommand in code-behind is setup like:</p>
  
  <pre><code>Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
     If (e.CommandName = "DeleteRow") Then
       //do stuff here
  </code></pre>
  
  <p>The GridView is data bound on Page Load as follows:</p>
  
  <pre><code>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
       Session("CalledModule") = "RCMT0021"
    Else
        With ViewState
             _intRepor = CInt(.Item("Report"))
        End With
    End If
       DataBind()   //Gridview Load
  End Sub
  </code></pre>
  
  <p>My questions:</p>
  
  <ol>
  <li>The row command event is never fired. The page just goes into the ELSE (of Not is Postback) in Page_Load</li>
  <li>How can I keep track of what all is typed in the "Comments" column of each row (a TEXTAREA), and save the data to the database when a SAVE CHANGES (form) button is clicked?</li>
  </ol>
  
  <p>Thanks!</p>
  
  <p>UPDATE:
  The Grid-View's Databinding is as follows:</p>
  
  <pre><code>Public Sub DataBind()
  Dim clsDatabase As New clsDatabase
  Dim cmd As New OleDbCommand()
  Try
   cmd.CommandText = "SELECT A, B FROM WHERE C = ? ORDER BY A"
     Dim report As New OleDbParameter("@Report", _intReportNumber)
     cmd.Parameters.Add(report)
  
     cmd.Connection = clsDatabase.Open_DB()
     Dim dReader As OleDbDataReader
     dReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
  
     Dim dt As New DataTable
     dt.Columns.Add(New DataColumn("PictureURL", GetType(String)))
     dt.Columns.Add(New DataColumn("Seq", GetType(Int16)))
     dt.Columns.Add(New DataColumn("ReportNumber", GetType(String)))
  
     Do While (dReader.Read())
        Dim dr As DataRow = dt.NewRow()
  
        _strComments = dReader(0).ToString
        dr("Seq") = dReader.GetInt16(1)
        dr("PictureURL") = "GetImages.aspx?report=" + _intReportNumber.ToString + "&amp;seq=" + dReader.GetInt16(1).ToString
        dr("ReportNumber") = _intReportNumber.ToString
        dt.Rows.Add(dr)
     Loop
  
     GridView1.DataSource = dt
     GridView1.DataBind()
  
    Catch err As Exception
   End Try
  End Sub
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/42oZC.png" alt="enter image description here"></p>
  
  <p>So basically, the GridView has three visible columns - a comments field, a picture field, and a field with a delete button (image) to delete the picture (and comments, if any) from the database. The 4th column is a hidden one, keeping track of the the Image ID of the images. I didn't include the picture and other columns for simplicity sake. </p>
  
  <ul>
  <li>The user can add comments, and when he clicks a 'SAVE CHANGES' button, the corresponding comments should get saved for the picture.</li>
  <li><strong>The 'SELECT IMAGE' opens up a ModalDialogBox which enables the user to select the image. When closed, it causes a postback, and rebinds the gridview to display the image the user just selected. Therefore, I need the GridView to rebind on postback, or a way around this.</strong> </li>
  <li>The delete imagebutton <strong>(in gridview)</strong> should delete the image and comments from the database.</li>
  </ul>
  
  <p>Thanks again!</p>