title: Update panel refresh ASP.Net gridview
body: <p>I have a ASP.Net Grid view inside a Update Panel. I show the data in a Modalpopup extender. I am also using entity framework. <strong>The code below works but I need to ensure that I am using the best practices</strong></p>
  
  <p>The ASP.Net Gridview </p>
  
  <pre><code> &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;   &lt;/asp:ScriptManager&gt;
   &lt;asp:UpdatePanel ID="UpdatePanel1"  UpdateMode="Conditional" runat="server"&gt;
      &lt;Triggers&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="grdOutput" /&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="btnDelete"  /&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="btnSave"  /&gt;
      &lt;/Triggers&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Button ID="btnNew" OnClick="btnNew_Click" Text=" new"  runat="server"/&gt;
              &lt;asp:GridView ID="grdOutput" runat="server" Width="200px" AutoGenerateColumns="False"  DataKeyNames="Id" &gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" /&gt;
                      &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /&gt;
                      &lt;asp:TemplateField HeaderText="Edit"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:LinkButton ID="lnkEdit" runat="server" OnClick="lnkEdit_Click"&gt;Edit&lt;/asp:LinkButton&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
           &lt;asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=FMPEntities" DefaultContainerName="FMPCommsEngEntities" EnableFlattening="False" EntitySetName="OutputTypes" EntityTypeFilter="OutputType"&gt;
           &lt;/asp:EntityDataSource&gt;
           &lt;asp:Panel ID="pnlEdit" runat="server" CssClass="modalPopup" style = "display:none"&gt;
       &lt;table &gt;
          &lt;tr&gt;&lt;td colspan="2"&gt; Output Type Details&lt;/td&gt;&lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="lblOutputTypeID" runat="server" Text="ID"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="txtOutPutTypeID" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
         &lt;/tr&gt;
         &lt;tr&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="lblName" runat="server" Text="Name"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="txtOutputTypeName" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
  
         &lt;/tr&gt;
         &lt;tr&gt;
             &lt;td&gt; &lt;asp:Button ID="btnSave" runat="server" OnClick="Save" Text="Save" /&gt;&lt;/td&gt;
             &lt;td&gt;&lt;asp:Button ID="btnCancel" runat="server" Text="Cancel"  /&gt;&lt;/td&gt;
             &lt;td&gt;&lt;asp:Button Id="btnDelete" runat="server" Text="Delete" OnClick="Delete" /&gt;&lt;/td&gt;
         &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Panel&gt; 
  &lt;asp:Panel ID="pnlAdd" runat="server" CssClass="modalPopup" style = "display:none"&gt;
      &lt;table &gt;
          &lt;tr&gt;&lt;td colspan="2"&gt; Output Type Details&lt;/td&gt;&lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="lblADDName" runat="server" Text="Name"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="txtAddName" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
         &lt;tr&gt;
             &lt;td&gt; &lt;asp:Button ID="btnADDSave" runat="server" OnClick="Insert" Text="Save" /&gt;&lt;/td&gt;
             &lt;td&gt;&lt;asp:Button ID="btnCancel1" runat="server" Text="Cancel"  /&gt;&lt;/td&gt;
         &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Panel&gt;
  &lt;cc1:ModalPopupExtender ID="popup" runat="server" CancelControlID="btnCancel" DropShadow="false"                                     PopupControlID="pnlEdit" TargetControlID = "link" BackgroundCssClass="modalBackground"&gt;
  &lt;/cc1:ModalPopupExtender&gt;
  &lt;cc1:ModalPopupExtender ID="AddPopup" runat="server" CancelControlID="btnCancel1" DropShadow="true" PopupControlID="pnlAdd" TargetControlID = "Addlink" BackgroundCssClass="modalBackground" &gt;     &lt;/cc1:ModalPopupExtender&gt; 
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>I need to refresh the gridview after the insert , update and delete. </p>
  
  <p>Below is the code I used. Is there a better way of refreshing the datasource. 
  I set the gridview datasource to an entitydatasource  and databind it after the  after each save, insert and delete.</p>
  
  <pre><code>Protected Sub Save(sender As Object, e As EventArgs)
      UpdateOutputType(Integer.Parse(txtOutPutTypeID.Text), txtOutputTypeName.Text)
      grdOutput.DataSource = EntityDataSource1
      grdOutput.DataBind()
  
  End Sub
  Protected Sub Delete(sender As Object, e As EventArgs)
      DeleteOutputType(Integer.Parse(txtOutPutTypeID.Text))
      grdOutput.DataSource = EntityDataSource1
      grdOutput.DataBind()
  End Sub
  </code></pre>
  
  <p>I tried to use <code>UpdatePanel1.update()</code> but the <code>gridview</code> did not refresh . </p>
  
  <p><strong>What is the best way to refresh the <code>gridview</code>?</strong>.</p>