title: "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
body: <p>I have 5 DropDownLists in GridView. I bind the grid with ObjectDataSource and also bind the DropDownLists that belongs to GridView with 5 ObjectDataSources. Every thing is working fine. I capture first DropDownList SelectedIndexChanged event in C# and i want to bind 2nd DropDownList. Here is the code that i am using to bind second dropdownlist:</p>
  
  <pre><code>protected void Level1DropdownList_SelectedIndexChanged(object sender, EventArgs e)
          {
              DropDownList level1List = sender as DropDownList;
              if (level1List != null)
              {
                  if (level1List.SelectedValue != "0")
                  {
                      // Bind Level 2 List
                      GridViewRow currentRow = AnnouncementLevelsGrid.Rows[AnnouncementLevelsGrid.EditIndex];
                      if (currentRow != null)
                      {
                          DropDownList level2List = currentRow.FindControl("Level2DropdownList") as DropDownList;
                          if (level2List != null)
                          {
                              level2List.DataSource = AnnouncementHelper.GetLevel2(level1List.SelectedValue, EmployerHelper.EmployerID);
                              level2List.DataTextField = "Level2";
                              level2List.DataValueField = "Level2Value";
                              level2List.DataBind();
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>Here is the asp.net code sample.</p>
  
  <pre><code>&lt;asp:GridView ID="AnnouncementLevelsGrid" runat="server" Width="99%" DataSourceID="AnnouncementLevelsDataSource"
                                                      CssClass="Grid" AutoGenerateColumns="False" GridLines="None" DataKeyNames="AnnouncementLevelID,AnnouncementId"
                                                      ViewStateMode="Enabled" OnRowCommand="AnnouncementLevelsGrid_RowCommand" OnRowDataBound="AnnouncementLevelsGrid_RowDataBound"
                                                      OnRowUpdating="AnnouncementLevelsGrid_RowUpdating"&gt;
                                                      &lt;HeaderStyle CssClass="GridHeader" /&gt;
                                                      &lt;RowStyle CssClass="GridRow" /&gt;
                                                      &lt;AlternatingRowStyle CssClass="GridAlternating" /&gt;
                                                      &lt;Columns&gt;
                                                          &lt;asp:TemplateField HeaderText="Level 1"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:Label ID="Level1Label" runat="server" Text='&lt;%# Eval("Level1").ToString() == "0" ? "ALL" : Eval("Level1") %&gt;'&gt;&lt;/asp:Label&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:DropDownList ID="Level1DropdownList" runat="server" AppendDataBoundItems="True"
                                                                      DataTextField="Level1" DataValueField="Level1Value" SelectedValue='&lt;%# Eval("Level1") %&gt;'
                                                                      AutoPostBack="True" DataSourceID="Level1DataSource" OnSelectedIndexChanged="Level1DropdownList_SelectedIndexChanged"&gt;
                                                                      &lt;asp:ListItem Text="All" Value="0"&gt;&lt;/asp:ListItem&gt;
                                                                  &lt;/asp:DropDownList&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                          &lt;asp:TemplateField HeaderText="Level 2"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:Label ID="Level2Label" runat="server" Text='&lt;%# Eval("Level2").ToString() == "0" ? "ALL" : Eval("Level2") %&gt;'&gt;&lt;/asp:Label&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:DropDownList ID="Level2DropdownList" runat="server" AppendDataBoundItems="True"
                                                                      DataTextField="Level2" DataValueField="Level2Value" SelectedValue='&lt;%# Eval("Level2") %&gt;'
                                                                      AutoPostBack="True" DataSourceID="Level2DataSource" OnSelectedIndexChanged="Level2DropdownList_SelectedIndexChanged"&gt;
                                                                      &lt;asp:ListItem Text="All" Value="0"&gt;&lt;/asp:ListItem&gt;
                                                                  &lt;/asp:DropDownList&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                          &lt;asp:TemplateField HeaderText="Level 3"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:Label ID="Level3Label" runat="server" Text='&lt;%# Eval("Level3").ToString() == "0" ? "ALL" : Eval("Level3") %&gt;'&gt;&lt;/asp:Label&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:DropDownList ID="Level3DropdownList" runat="server" AppendDataBoundItems="True"
                                                                      DataTextField="Level3" DataValueField="Level3Value" SelectedValue='&lt;%# Eval("Level3") %&gt;'
                                                                      AutoPostBack="True" DataSourceID="Level3DataSource" OnSelectedIndexChanged="Level3DropdownList_SelectedIndexChanged"&gt;
                                                                      &lt;asp:ListItem Text="All" Value="0"&gt;&lt;/asp:ListItem&gt;
                                                                  &lt;/asp:DropDownList&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                          &lt;asp:TemplateField HeaderText="Level 4"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:Label ID="Level4Label" runat="server" Text='&lt;%# Eval("Level4").ToString() == "0" ? "ALL" : Eval("Level4") %&gt;'&gt;&lt;/asp:Label&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:DropDownList ID="Level4DropdownList" runat="server" AppendDataBoundItems="True"
                                                                      DataTextField="Level4" DataValueField="Level4Value" SelectedValue='&lt;%# Eval("Level4") %&gt;'
                                                                      AutoPostBack="True" DataSourceID="Level4DataSource" OnSelectedIndexChanged="Level4DropdownList_SelectedIndexChanged"&gt;
                                                                      &lt;asp:ListItem Text="All" Value="0"&gt;&lt;/asp:ListItem&gt;
                                                                  &lt;/asp:DropDownList&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                          &lt;asp:TemplateField HeaderText="Level 5"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:Label ID="Level5Label" runat="server" Text='&lt;%# Eval("Level5").ToString() == "0" ? "ALL" : Eval("Level5") %&gt;'&gt;&lt;/asp:Label&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:DropDownList ID="Level5DropdownList" runat="server" AppendDataBoundItems="True"
                                                                      DataTextField="Level5" DataValueField="Level5Value" SelectedValue='&lt;%# Eval("Level5") %&gt;'
                                                                      DataSourceID="Level5DataSource"&gt;
                                                                      &lt;asp:ListItem Text="All" Value="0"&gt;&lt;/asp:ListItem&gt;
                                                                  &lt;/asp:DropDownList&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="18%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                          &lt;asp:TemplateField ShowHeader="False"&gt;
                                                              &lt;ItemTemplate&gt;
                                                                  &lt;asp:LinkButton ID="EditLink" runat="server" CausesValidation="False" CommandName="Edit"
                                                                      Text="Edit" ToolTip="Edit"&gt;&lt;img src="images/edit.png" alt="Edit" style="border-width: 0px;" /&gt;&lt;/asp:LinkButton&gt;
                                                              &lt;/ItemTemplate&gt;
                                                              &lt;EditItemTemplate&gt;
                                                                  &lt;asp:LinkButton ID="UpdateLink" runat="server" CausesValidation="True" CommandName="Update"
                                                                      Text="Update" ToolTip="Update"&gt;&lt;img src="images/Update-Grd.png" alt="Update" style="border-width: 0px;" /&gt;&lt;/asp:LinkButton&gt;
                                                                  &amp;nbsp;&lt;asp:LinkButton ID="CancelLink" runat="server" CausesValidation="False" CommandName="Cancel"
                                                                      Text="Cancel" ToolTip="Cancel"&gt;&lt;img src="images/Cancel-Grd.png" alt="Cancel" style="border-width: 0px;" /&gt;&lt;/asp:LinkButton&gt;
                                                              &lt;/EditItemTemplate&gt;
                                                              &lt;HeaderStyle HorizontalAlign="Center" Width="10%" /&gt;
                                                              &lt;ItemStyle HorizontalAlign="Center" Width="10%" /&gt;
                                                          &lt;/asp:TemplateField&gt;
                                                      &lt;/Columns&gt;
                                                      &lt;EmptyDataTemplate&gt;
                                                          No Announcements Found.
                                                      &lt;/EmptyDataTemplate&gt;
                                                  &lt;/asp:GridView&gt;
                                                  &lt;asp:ObjectDataSource ID="AnnouncementLevelsDataSource" runat="server" SelectMethod="GetAnnouncementLevels"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="AnnouncementLevelsDataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="announcementID" DbType="Int64" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
                                                  &lt;asp:ObjectDataSource ID="Level1DataSource" runat="server" SelectMethod="GetLevel1"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level1DataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="employerID" DbType="Int64" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
                                                  &lt;asp:ObjectDataSource ID="Level2DataSource" runat="server" SelectMethod="GetLevel2"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level2DataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="employerID" DbType="Int64" /&gt;
                                                          &lt;asp:Parameter Name="cc1" DbType="String" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
                                                  &lt;asp:ObjectDataSource ID="Level3DataSource" runat="server" SelectMethod="GetLevel3"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level3DataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="employerID" DbType="Int64" /&gt;
                                                          &lt;asp:Parameter Name="cc2" DbType="String" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
                                                  &lt;asp:ObjectDataSource ID="Level4DataSource" runat="server" SelectMethod="GetLevel4"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level4DataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="employerID" DbType="Int64" /&gt;
                                                          &lt;asp:Parameter Name="cc3" DbType="String" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
                                                  &lt;asp:ObjectDataSource ID="Level5DataSource" runat="server" SelectMethod="GetLevel5"
                                                      TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level5DataSource_Selecting"&gt;
                                                      &lt;SelectParameters&gt;
                                                          &lt;asp:Parameter Name="employerID" DbType="Int64" /&gt;
                                                          &lt;asp:Parameter Name="cc4" DbType="String" /&gt;
                                                      &lt;/SelectParameters&gt;
                                                  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>When i click edit button in grid view, all the dropdownlists render them in edit mode. They are also populating data correctly. Now when i change the first drop down list item in order to populate the second one, it throws the following exception :</p>
  
  <p><strong>Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</strong></p>
  
  <p>Can any body tell me how can i get rid of this problem. Do i need to handle another event of grid to bind the dropdown correctly? Also i want grid row still in edit mode after binding dropdown.</p>