title: GridView inside UpdatePanel not refreshing without a call to code behind
body: <p>I am new to ASP.Net and I am confused about the way a GridView control works inside an UpdatePanel. </p>
  
  <p>I have read the documentation <a href="http://msdn.microsoft.com/en-us/library/bb386454%28v=vs.100%29.aspx" rel="nofollow">here</a> which states "By default, any postback control inside an UpdatePanel control causes an asynchronous postback and refreshes the panel's content." yet, when I place a GridView and a Button control inside the  element, unless the button has a defined OnClick event to do grid1.DataBind();, the grid will NOT refresh its data. Also, I have tried by specifying an AsyncPostBackTrigger on the UpdatePanel for the Button, but again I got the same behaviour. Now, I noticed that the UpdatePanel DOES refresh when I press a Button without OnClick event, however the GridView inside it does not. Please can you shed some light on this? Must I always have that call to code behind to explicitly refresh it?</p>
  
  <p>My connection string in Web.Config</p>
  
  <pre><code>    &lt;connectionStrings&gt;
          &lt;add name="myConnectionString"
               connectionString="Data Source=XXXXX;Initial Catalog=XXXX;Persist Security Info=True;User ID=XXXXX;Password=XXXXX"
               providerName="System.Data.SqlClient" /&gt;
      &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>My Default.aspx</p>
  
  <pre><code> &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EmptyWebApp.Default" %&gt;
   &lt;!DOCTYPE html&gt;
   &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
   &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt;
   &lt;body&gt;
       &lt;form id="form1" runat="server"&gt;
           &lt;div&gt;
               &lt;asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" /&gt;
               &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;
                   &lt;ContentTemplate&gt;
                       &lt;asp:GridView ID="grid1" runat="server" DataSourceID="SQLDevelopment" AutoGenerateColumns="False"&gt;
                           &lt;Columns&gt;
                               &lt;asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" /&gt;
                               &lt;asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" /&gt;
                           &lt;/Columns&gt;
                       &lt;/asp:GridView&gt;
                       &lt;asp:SqlDataSource ID="SQLDevelopment" runat="server"
                      ConnectionString="&lt;%$ ConnectionStrings:myConnectionString %&gt;" 
                      SelectCommand="SELECT * FROM [TestTableA]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;%=DateTime.Now.ToString()%&gt; &lt;br /&gt;
                  &lt;asp:Button ID="btnRefresh" runat="server" Text="Refresh without C# event"/&gt;
                  &lt;asp:Button ID="btnRefresh1" runat="server" Text="Refresh with C# event" OnClick="btnRefresh1_Click"/&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
      &lt;/div&gt;
   &lt;/form&gt;&lt;/body&gt;&lt;html&gt;
  </code></pre>
  
  <p>My Code behind for btnRefresh1</p>
  
  <pre><code>    protected void btnRefresh1_Click(object sender, EventArgs e)
      {
          grid1.DataBind();
      }
  </code></pre>
  
  <p>THANK YOU</p>