Ian
Ian

Reputation: 1504

Access model bound item inside nested UpdatePanel

What is the correct method to access the data-bound item inside of a nested UpdatePanel? I've recently discovered model binding and love the strongly-typed binding it offers, but I have a scattering of UpdatePanels throughout the page, and it seems to break access to the Item object. If the entire databound control is inside the UpdatePanel I have no problem. This works:

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Repeater runat="server" ID="myRepeater" ItemType="Test.Person">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Item.Name %>' /><br />
            </ItemTemplate>
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

But if the UpdatePanel is inside the bound control, I no longer have access to Item. This does not work:

<asp:Repeater runat="server" ID="myRepeater" ItemType="Test.Person">
    <ItemTemplate>
        <asp:UpdatePanel runat="server">
            <ContentTemplate>
                <asp:Label runat="server" Text='<%# Item.Name %>' /><br />  // <-- Problem line
            </ContentTemplate>
        </asp:UpdatePanel>
    </ItemTemplate>
</asp:Repeater>

CS0103: The name 'Item' does not exist in the current context

I fumbled my way onto a clunky solution, which is this

((Person)GetDataItem()).Name

But I desperately hope this is not the best way of accomplishing the task.

Upvotes: 1

Views: 98

Answers (0)

Related Questions