views:

140

answers:

1

Hi folks,

Can I place a asp:datalist inside a repeater control and databind it for each time its repeated? Using VB.NET btw..

Cheers! --Jonesy

+1  A: 

Steps:
1. Nest the DataList in the Repeater
2. Bind each repeated Datalist during the Repeater's ItemDataBound event
3. Turn off their ViewStates,if they are not required.

Update:

i.e.

Script Side:

<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:DataList ID="DataList1" runat="server">
            </asp:DataList>
        </ItemTemplate>
        </asp:Repeater>

In Code:

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        Dim DataList1 As DataList = DirectCast(e.Item.FindControl("DataList1"), DataList)
...Databind here ....

End Sub
Brij
Hi thanks for the reply. How do i do step 2? this is what i have done to databind the repeater: Repeater1.DataSource = dtAssets Repeater1.DataBind()How can I access a control inside that repeater? I've tried this:Dim DataList1 As DataList = DirectCast(Repeater1.FindControl("DataList1"), DataList)But i get an error saying:Object reference not set to an instance of an object.please help! -- Jonesy
iamjonesy
sorry new to repeaters, what is the ItemDataBound?
iamjonesy
Hi i figured it out. You were right about needing it in the ItemDataBind. Thanks!
iamjonesy
oh one more question if you'll help me. Can I pass a variable to the repeaters ItemDataBound sub? It would be a variable bound to the repeater.
iamjonesy
You can show any databound element to UI using #Eval and can access on server side using e.item.DataItem
Brij
I ended up using a hidden label to use variables. I know its probably not the way its supposed to be but it works well. On repeater databind i set the text of the label to the id of the asset (in this case) then when i call the itemdatabind sub to get the asset history I use the labels text value. --jonesy
iamjonesy