title: How to handle exceptions with a SqlDataSource
body: <p>I have a SqlDataSource that is supplying data to my GridView. Thats all i am using on my form, thus i have NO code behind at all. But somewhere i need a TRY CATCH block just in case my connection get's lost. What code must i place where?</p>
  
  <p>If i get a error i want my lblMessage Text to be "No connection".</p>
  
  <p><strong>Edit</strong></p>
  
  <p>My GridView in my Machine.aspx</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
      Height="209px" PageSize="7" Width="331px" AllowSorting="True" 
                  DataSourceID="SqlDataSource1"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="Total" HeaderText="Total" ReadOnly="True" 
              SortExpression="Total" DataFormatString="{0:R#,###,###}" &gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="b134_rmcid" HeaderText="Machine"  ReadOnly="True" 
              SortExpression="b134_rmcid" &gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="b134_recdate" DataFormatString="{0:d/MM/yyyy}" 
              HeaderText="Date" ReadOnly="True" SortExpression="b134_recdate" &gt;
              &lt;HeaderStyle HorizontalAlign="Left" /&gt;
          &lt;/asp:BoundField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>My Connection right under my Gridview in my Machine.aspx</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ODBC_ConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:ODBC_ConnectionString.ProviderName %&gt;" 
  
      SelectCommand="SELECT SUM(b134_nettpay) AS Total, b134_rmcid, b134_recdate FROM B134HRE" 
      onselected="SqlDataSource1_Selected"&gt;
  
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>My Code in my Code Behind file in my Machine.aspx.cs</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      lblError.Text = "hello there";
      SqlDataSource1.Selected += new SqlDataSourceStatusEventHandler(SqlDataSource1_Selected);
  
  
  }
  
  
  protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
  {
  
    if (e.ExceptionHandled)
     {
  
         lblError.Text = "There is a problem";  
  
     }
  
  }
  </code></pre>
  
  <p>And still for some ready when i place a BreakPoint in my Selected Event it does not even get to it???</p>
  
  <p>Why?</p>