title: Database updating, but GridView remains unchanged
body: <p>I've got my code to delete rows out of the database when the user clicks on the Delete button in my GridView, but the GridView isn't updating to reflect the new data changes.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    &lt;asp:GridView runat="server" ID="grdQuestions" AutoGenerateColumns="false" Width="100%" CellSpacing="10"
           PagerSettings-Visible="true"&gt;
          &lt;HeaderStyle CssClass="aspNetHeader" /&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="QuestionID" HeaderText="QID" /&gt;
              &lt;asp:BoundField DataField="ModuleID" HeaderText="Mod #" /&gt;
              &lt;asp:BoundField DataField="QuestionText" HeaderText="Question" /&gt;
              &lt;asp:BoundField DataField="CorrectAnswer" HeaderText="Answer" /&gt;
              &lt;asp:BoundField DataField="AnswerNote" HeaderText="Note" /&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:HyperLink runat="server" ID="lnkEdit" Text="Edit"&gt;&lt;/asp:HyperLink&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:LinkButton runat="server" ID="lnkDelete" Text="Delete" CommandArgument='&lt;%# eval("QuestionID") %&gt;'&gt;&lt;/asp:LinkButton&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  
  Protected Sub grdQuestions_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdQuestions.RowCommand
      If e.CommandName = "Delete" Then
  
          sql = "delete from tmp_Questions where QuestionID = " &amp; e.CommandArgument
          Dim cmd As New SqlCommand(sql, d.SQLConnection)
  
          d.SQLConnection.Open()
          cmd.ExecuteNonQuery()
          d.SQLConnection.Close()
  
          GetModuleData()
      End If
  End Sub
  
  Protected Sub grdQuestions_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles grdQuestions.RowDeleting
      GetModuleData()
  End Sub
  
  Private Sub GetModuleData()
      ' ddlModules is a drop down where the user can select a module to filter questions by.
      Dim selid As Integer = ddlModules.SelectedItem.Value
      sql = "select QuestionID, ModuleID, LEFT(QuestionText, charindex(' ', QuestionText, 30)) as QuestionText, CorrectAnswer," &amp; vbCrLf &amp; _
          "AnswerNote from tmp_Questions" &amp; vbCrLf &amp; _
          "where ModuleID = " &amp; selid &amp; vbCrLf &amp; _
          "order by ModuleID"
      Dim cmd As New SqlCommand(sql, d.SQLConnection)
      cmd.CommandText = sql
  
      QuestionAdapter.SelectCommand = cmd
      QuestionAdapter.Fill(QuestionData)
  
      If QuestionData.Tables(0).Rows.Count &gt; 0 Then
  
          grdQuestions.DataSource = QuestionData
          grdQuestions.DataBind()
      End If
  End Sub
  </code></pre>
  
  <p>Thanks in advance for having a look!</p>
  
  <p><strong>EDIT 1:</strong><br>
  Did some stepping through the code and found that <code>e.CommandArgument</code> is not getting a value in <code>grdQuestions_RowCommand</code></p>
  
  <p><strong>EDIT 1 (Revised):</strong><br>
  The fact that <code>e.CommandArgument</code> wasn't getting a value was my mistake. I'd changed the way it's value was being assigned without removing the previous method.
  The code runs through <code>grdQuestions_RowCommand</code> and then goes into <code>grdQuestions_RowDeleting</code> and then executes <code>GetModuleData</code>.<br>
  I have a feeling that to view changes to the grid, a PostBack might be required, but I've removed all DataBinding to an <code>If Not IsPostBack Then</code> block because the alternative caused problems with the DropDownList whose selection is used as a reference to populate the grid (ddlModules selected the Module whose Questions will display in the grid).</p>