C# set custom UserControl variables when its in a Repeater

Posted by tnriverfish on Stack Overflow See other posts from Stack Overflow or by tnriverfish
Published on 2010-03-17T18:45:10Z Indexed on 2010/03/17 18:51 UTC
Read the original article Hit count: 324

Filed under:
|
|
|
<%@ Register Src="~/Controls/PressFileDownload.ascx" TagName="pfd" TagPrefix="uc1" %>

<asp:Repeater id="Repeater1" runat="Server" OnItemDataBound="RPTLayer_OnItemDataBound">
 <ItemTemplate>
   <asp:Label ID="LBLHeader" Runat="server" Visible="false"></asp:Label>
   <asp:Image ID="IMGThumb" Runat="server" Visible="false"></asp:Image>
   <asp:Label ID="LBLBody" Runat="server" class="layerBody"></asp:Label>
   <uc1:pfd ID="pfd1" runat="server" ShowContainerName="false" ParentContentTypeId="55" />
   <asp:Literal ID="litLayerLinks" runat="server"></asp:Literal>
 </ItemTemplate>
</asp:Repeater>

System.Web.UI.WebControls.Label lbl;
System.Web.UI.WebControls.Literal lit;
System.Web.UI.WebControls.Image img;
System.Web.UI.WebControls.HyperLink hl;
System.Web.UI.UserControl uc;

I need to set the ParentItemID variable for the uc1:pdf listed inside the repeater. I thought I should be able to find uc by looking in the e.Item and then setting it somehow. I think this is the part where I'm missing something.

uc = (UserControl)e.Item.FindControl("pfd1");
if (uc != null) { uc.Attributes["ParentItemID"] = i.ItemID.ToString(); }

Any thoughts would be appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about repeater