Dynamic property assignment in usercontrol in an ASP.NET repeater

I currently have a repeater control, and inside the itemtemplate element I have a usercontrol. This usercontrol is displayed correctly, but I'm trying to assign a dataitem to a property in the repeater control.

<asp:Repeater ID="Repeater1" DataSourceID="EntityDataSource" runat="server"> <ItemTemplate> <uc1:Request ID="Request1" runat="server" RequestId='<%# Eval("RequestId") %>' /> </ItemTemplate> 

RequestId is just Int32. He just doesn't appoint him.

I can put eval beyond the limits of usercontrol only in itemtemplate, and it correctly outputs the correct id.

If I delete the entire eval and just type in a number, then it works fine.

Any help was appreciated.

[UPDATE]: issue resolved

I used EntityDataSource and it was automatically bound to the repeater. He printed all the information from the database on the screen without any codes. But when I entered the code for Repeater1.DataBind (); he started to work.

I don’t know why, but hey he decided. Now it successfully passes the value. I believe this has something to do with the page life cycle.

+6
c # user-controls
source share
3 answers

If you just bind to a collection of int repeaters, you need to use this:

 <uc1:Request ID="Request1" runat="server" RequestId='<%# Container.DataItem %>' /> 

And don't forget to call DataBind () for the repeater or for the page where there is a repeater control.

+4
source share

Do you miss ' at the end?

change the following:

 RequestId='<%# Eval("RequestId") %> /> 

to

 RequestId='<%# Eval("RequestId") %>' /> 
+2
source share

You can implement this using the ItemDataBound event to control the repeater so that you can set a dynamic property for the control.

0
source share

All Articles