Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically assigning a property in a usercontrol in an ASP.NET repeater control

I currently have a repeater control and inside the itemtemplate I have a usercontrol. This usercontrol renders correctly, but I am 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 an Int32. It just doesn't assign it.

I can put the eval outside of the usercontrol just in the itemtemplate and it correctly outputs the right id.

If I remove the whole eval and just type a number in then it works fine.

Any help appreciated.

[UPDATE] : Issue Solved

I was using an EntityDataSource and this automatically binded to the repeater. It printed out all the information from the database on the screen without any codebehind. But when I put in the code behind Repeater1.DataBind(); it then started to work.

I don't know why, but hey it's solved. It now successfully passes the value through. I imagine it has something to do with the page lifecycle.

like image 834
Adam Avatar asked Dec 13 '10 09:12

Adam


People also ask

Which property must be set and which method must be called in your code to bind the data from some data source to the Repeater control?

When you set the DataSource property you must manually write the code to bind to the data source. If the data source specified by the DataSource property contains multiple sources of data, use the DataMember property to specify the specific source to bind to the control.

What is ASP Repeater?

The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items. Repeater is a Data Bind Control. Data Bind Controls are container controls.


2 Answers

If you just bind with repeater collection of int, you need use this:

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

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

like image 101
Dima Shmidt Avatar answered Nov 11 '22 17:11

Dima Shmidt


Are you missing a ' at the end?

change following:

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

to

RequestId='<%# Eval("RequestId") %>' />
like image 45
decyclone Avatar answered Nov 11 '22 15:11

decyclone