title: How to refresh GridView after data insert?
body: <p>I have a GridView and when some data has been inserted I have called the DataBind() method on the GridView and the ObjectDataSource the GridView is bound to, but the GridView does not display the new data. How do I get it to refresh?</p>
  
  <p>Here's my ASP.NET code:</p>
  
  <pre><code>&lt;asp:GridView 
      ID="grdOrderSignals" 
      runat="server" 
      DataSourceID="srcOrderSignals" 
      DataKeyNames="signal"
      EmptyDataText="There are no signals for this order"
      AutoGenerateColumns="False"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="signal" HeaderText="Signal Id"  ReadOnly="True" /&gt;
          &lt;asp:BoundField DataField="description" HeaderText="Description"  ReadOnly="True" /&gt;
          &lt;CustomControls:DeleteButtonField ConfirmText="Delete this order signal?" Text="Del" /&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;  
  
  &lt;CustomControls:CustomObjectDataSource
      id="srcOrderSignals" 
      TypeName="DatabaseComponent.DBUtil" 
      SelectMethod="GetOrderSignals" 
      DeleteMethod="DeleteOrderSignal" 
      EnableCaching="false"
  
      runat="server"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedValue" /&gt;
      &lt;/SelectParameters&gt; 
      &lt;DeleteParameters&gt;
          &lt;asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedValue" /&gt;        
          &lt;asp:ControlParameter Name="signal" ControlID="grdOrderSignals" PropertyName="SelectedValue" /&gt;                    
      &lt;/DeleteParameters&gt;           
  &lt;/CustomControls:CustomObjectDataSource&gt; 
  
  &lt;asp:Button ID="btnAddOrderSignal" runat="server" Text="Add Order Signal" OnClick="btnAddOrderSignal_Click" /&gt;
  &lt;asp:DropDownList ID="ddlSignals" runat="server" Visible="false" /&gt;
  &lt;asp:Button ID="btnInsertOrderSignal" runat="server" Text="Add" Visible="false" OnClick="btnInsertOrderSignal_Click" /&gt;
  </code></pre>
  
  <p>Here's my code-behind to handle the click events:</p>
  
  <pre><code>protected void btnAddOrderSignal_Click(object sender, EventArgs e)
  {
      FillSignals();
      btnAddOrderSignal.Visible = false;
      ddlSignals.Visible = true;
      btnInsertOrderSignal.Visible = true;
  
  }
  
  protected void btnInsertOrderSignal_Click(object sender, EventArgs e)
  {
      InsertOrderSignal();
      btnAddOrderSignal.Visible = true;
      ddlSignals.Visible = false;
      btnInsertOrderSignal.Visible = false;
      srcOrderSignals.DataBind();
      grdOrderSignals.DataBind();      
  }
  
  protected void InsertOrderSignal()
  {
      DBUtil DB = new DBUtil();
      int orderId = (int)grdOrders.SelectedValue;
      string signalId = ddlSignals.SelectedValue;
      DB.InsertOrderSignal(orderId, signalId);
  }
  
  protected void FillSignals()
  {
      DBUtil DB = new DBUtil();
      DataTable od = DB.GetOrderDetails((int)grdOrders.SelectedValue);
      int strategyId = (int)od.Rows[0]["strategyId"];
  
      ddlSignals.DataSource = DB.GetSignals(strategyId);
      ddlSignals.DataTextField = "signalId";
      ddlSignals.DataValueField = "signalId";
      ddlSignals.DataBind();      
  }
  </code></pre>
  
  <p>Do I need to call DataBind() on both objects? What have I done wrong here?</p>
  
  <p>Thanks!</p>