开发者

Passing in a value to a usercontrol through a foreach loop

in my asp.net mark up I have a foreach loop that iterates t开发者_JS百科hrough a simple list. In this foreach loop I am adding a new user control and attempting to pass in the value from the loop. However, this value just wont budge and get inside that damn control! Anyone have any suggestions?

<%foreach (userInfo i in this.items)
    { %>  
        <uc1:ItemControl ID="ItemControl" runat="server" UserID='<%#Eval("userID") %>'/>
<%} %>

userID is a public property in the control, when it goes to set, the value is just literally : <%#Eval("userID") %>. I've tried #Bind and =Value but nothing seems to work.

Any help would be appreciated!


Looks like the perfect use case for a repeater:

<asp:Repeater runat="server" id="myRepeater">
   <uc1:ItemControl ID="ItemControl" runat="server" />
</asp:Repeater>

You can databind your list (this.items) to the repeater and in the code behind, in the DataBind event set the UserID property of the ItemControl control.

The reason your approach will not work is that IDs have to be unique in a page.


Try use a Repeater control for your purpose

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜