title: TargetInvocationException: Exception has been thrown by the target of an invocation. on Data Bind
body: <p>I'm trying to bind a GridView to datasource on RowEditing event, but it throws an exception:</p>
  
  <blockquote>
    <p>[TargetInvocationException: Exception has been thrown by the target of an invocation.]
    Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</p>
  </blockquote>
  
  <pre><code>lblackout = EXMailbox.GetBlackouts();
  BlackoutGridView.DataSource=lblackout;
  
  
  protected void BlackoutGridView_RowEditing(object sender, GridViewEditEventArgs e)
  {
          BlackoutGridView.EditIndex = e.NewEditIndex;
          BlackoutGridView.DataSource = lblackout;  //Throws exception here.
          BlackoutGridView.DataBind();
  }
  
  
              &lt;asp:GridView ID="BlackoutGridView" runat="server" AutoGenerateColumns="False" 
                  OnRowDeleting="BlackoutGridView_RowDeleting" 
                  OnRowEditing="BlackoutGridView_RowEditing" 
                  onrowcancelingedit="BlackoutGridView_RowCancelingEdit"&gt;                            
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="BlackoutId" HeaderText="BlackoutId" &gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:TemplateField HeaderText="Region"&gt;
                          &lt;EditItemTemplate&gt;
                          &lt;asp:DropDownList ID="DropDownList11" runat="server" Text='&lt;%# Bind("Region") %&gt;' 
                                  DataSourceID="lblackout" DataTextField="Region" DataValueField="Region"&gt;&lt;/asp:DropDownList&gt;
                              &lt;asp:ObjectDataSource ID="lblackout" runat="server" SelectMethod="GetDataItem" 
                                  TypeName="Exchange.MailboxMove.WebUI.BlackoutScreen"&gt;&lt;/asp:ObjectDataSource&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Region") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:BoundField HeaderText="Server" DataField="Server"&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="From Date" DataField="StartDateTime" 
                          DataFormatString="{0:D}"&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="To Date" DataField="EndDateTime" 
                          DataFormatString="{0:D}"&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="From Time" DataField="StartDateTime" 
                          DataFormatString="{0:t}"&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:BoundField HeaderText="To Time" DataField="EndDateTime" 
                          DataFormatString="{0:t}"&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:CheckBoxField HeaderText="IsWeekly" DataField="IsWeekly"&gt;
                      &lt;/asp:CheckBoxField&gt;
                      &lt;asp:CommandField DeleteText="Cancel" HeaderText="Action" 
                          ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" &gt;
                      &lt;/asp:CommandField&gt;
  </code></pre>