Binding data in UpdatePanel inside Data-Bound controls

The following code snippet is an example of data-binding inside Repeater control:

<asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                        <%# DataBinder.Eval(Container.DataItem, "EmployeeName") %>
            </ItemTemplate>
        </asp:Repeater>

The above code is working fine. Now we place an UpdatePanel inside ItemTemplate and binding the same information again

<asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <%# DataBinder.Eval(Container.DataItem, "EmployeeName") %>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ItemTemplate>
        </asp:Repeater>

In the first example (without UpdatePanel) "Container" refers to Repeater control, while in second example "Container" refers to UpdatePanel.

This time, you'll get an error 'System.Web.UI.Control' does not contain a definition for 'DataItem' and no extension method 'DataItem' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)

To get rid from this, we'll use Interface "IDataItemContainer" which enables data-bound control containers to identify a data item object for simplified data-binding operations. And Change the underlined code to

        <%# DataBinder.Eval(((IDataItemContainer)Container).DataItem, "EmployeeName") %>

Note: I used Repeater in the examples, written above. However, the same is applicable for other Data-Bound controls, as GridView, DataList, DataGrid, etc.