Domanda

I have a formview and inside it's itemtemplate a repeater. I need to access the dataitem from formview inside the repeater.

Something like this

<asp:FormView runat="server" ID="EvaForm" ItemType="Item1" DataKeyNames="ProfileId" EnableViewState="true">
  <ItemTemplate>
   <asp:Repeater runat="server" ID="ProfileImages" ItemType="ProfileImage">
    <ItemTemplate>
     <a href="<%# LinkHelpers.GetProfilePath(Item.ProfileId, >>>>ITEM1 HERE<<<<.CreateDate) & Item.ImagePath%>" onclick="return false;">

An example with EVAL also together with an example with ItemType would be greatly appreciated. All this is inside a User Control, don't think this will make difference.

Thanks in advance

È stato utile?

Soluzione

Try this code:

<ItemTemplate>
    <a href="<%# LinkHelpers.GetProfilePath(Item.ProfileId, DataBinder.Eval(Container.NamingContainer.NamingContainer, "DataItem.CreateDate").ToString()) + Item.ImagePath %>" onclick="return false;">
</ItemTemplate>

Alternatively, you can use server controls to display hyperlinks and set the NavigateUrl property in code-behind:

<asp:Repeater runat="server" ID="ProfileImages" ItemType="ProfileImage" OnItemDataBound="ProfileImages_ItemDataBound">
    <ItemTemplate>
        <asp:HyperLink runat="server" ID="ProfileLink" OnClientClick="return false;" />
    </ItemTemplate>
<asp:Repeater>

Code-behind:

protected void ProfileImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    var profileImage = (ProfileImage) e.Item.DataItem;

    ((HyperLink) e.Item.FindControl("ProfileLink")).NavigateUrl = LinkHelpers.GetProfilePath(profileImage.ProfileId, ((Item1) EvaForm.DataItem).CreateDate.ToString()) + profileImage.ImagePath;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top