【发布时间】:2011-07-24 11:49:44
【问题描述】:
我在转发器内有一个用户控件,该控件由 sqldatasource 绑定。我收到以下错误: Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。 编辑:不要介意我脸上有鸡蛋。我收到了这个数据绑定错误,因为我将它绑定到其他地方,以便解决我上周五的真正问题,但我忘记了。
我真正的问题是: 用户控件在属性设置之前被绑定,因此看起来好像它们从未设置过。单步执行时,我看到他们在属性上的集合被击中之前被击中。例如,如果我将 放在用户控件之前,我将看到显示的 ID,但随后用户控件将显示一个空数据模板,因为它传递的 ID 为 0。
<asp:SqlDataSource ID="sqlFacilityAddresses" runat="server" DataSourceMode="DataSet" SelectCommandType="StoredProcedure" SelectCommand="SP_Facility_GetAddresses" ConnectionString="<%$ ConnectionStrings:Trustaff_ESig2 %>">
<SelectParameters>
<asp:Parameter Name="Facility_ID" DbType="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Repeater ID="repeaterAddresses" DataSourceID="sqlFacilityAddresses" runat="server">
<ItemTemplate>
<Select:Address ID="AddressControl" runat="server" AddressID='<%# EVal("Address_ID") %>' />
</ItemTemplate>
</asp:Repeater>
【问题讨论】: