>Thank you! That helped quite a bit. I can now get the user control to
>be called multiple times and the template html is displayed. Now I'm
>control.
>set to an instance of an object.
Quote:
>>First add the user control to the page declaration
>>>
>><%@Register Tagname="usercontrol" Tagprefix="usa"
>>src="~/controls/usercontrol.ascx"%>
>>>
>>then put the user control in the repeater
>>>
>> <asp:Repeater id="Repeater1" runat="server"
>>OnItemDataBound="processList">
>> <ItemTemplate><usa:usercontrol runat="Server" id="uscControl"
>>/></ItemTemplate>
>> </asp:Repeater>
>>>
>>then in the codebehind
>>>
>>Private Sub processList(ByVal sender As Object, ByVal e As
>>System.Web.UI.WebControls.RepeaterItemEventArg s)
>>>
>> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
>>ListItemType.AlternatingItem Then
>>>
>> Dim usc As your_control = e.Item.FindControl("uscControl")
>>>
>> 'now you can access all of the public properties and methods of
>>the usercontrol, for example
>>>
>> usc.LabelSet("test",true,"test1")
>>>
>> 'and so on
>>>
>> End If
>>>
>>End Sub
>>>
>>>
>>--
>>David Lozzi
>>
dlozzi@(remove)delphi-ts.com
>>
www.delphi-ts.com
>>>
>>"fernandezr" <robert.fernandez@gmail.comwrote in message
>>news:1152221976.111980.264830@s26g2000cwa.google groups.com...
>>I would like to use a user control as a template inside a repeater.
>Some of the fields in the control should be hidden depending on
>whether
>or not there is data. I'm still a ASP .Net newbie so the way I'm
>going
>about doing this might be a little off. I'd appreciate some help.
>>
>Below is the code I have thus far but I'm not sure how to reference
>the
>user control within the foreach loop.
>>
> <asp:Panel ID="pnlRosterProfile" runat="Server" />
>>
> <asp:Repeater ID="rptRoster" runat="Server" >
> <ItemTemplate>
> </ItemTemplate>
> </asp:Repeater>
>>
>Code behind:
>>
> DataSet DS = SQLRoutines.GetProfiles(strUID, strCCYYS,
>strRosterType);
> DataRow[] foundRows = DS.Tables[0].Select();
> foreach (DataRow dr in foundRows)
> {
>>
> [User control here?]
> }
>>
>>
>>
>-------------------------------------------------
>User control:
>>
><%@ Control Language="C#" AutoEventWireup="true"
>CodeFile="ucProfile.ascx.cs" Inherits="controls_ucRosterProfile" %>
>>
> <asp:Panel ID="pnlProfile" runat="Server">
> <asp:Table ID="tblProfile" runat="Server">
> <asp:TableRow>
> <asp:TableCell>
> <asp:Image ID="imgPhoto" runat="Server" />
> </asp:TableCell>
> <asp:TableCell>
> <asp:Label ID="lblNameDesc" runat="Server"
>Font-Bold="true" Text="Name" />
> <asp:Label ID="lblName" runat="Server" Text="" />
> <br />
> <asp:Label ID="lblEmailDesc" runat="Server"
>Font-Bold="true" Text="Email" />
> <asp:Label ID="lblEmail" runat="Server" Text="" />
> <br />
> <asp:Label ID="lblEmployerDesc" runat="Server"
>Font-Bold="true" Text="Employer" />
> <asp:Label ID="lblEmployer" runat="Server" Text="" />
> <br />
> <asp:Label ID="lblJobTitleDesc" runat="Server"
>Font-Bold="true" Text="Name" />
> <asp:Label ID="lblJobTitle" runat="Server" Text="" />
> <br />
>>
> </asp:TableCell>
> </asp:TableRow>
> </asp:Table>
> </asp:Panel>
>>
>>
>user control code behind:
>>
> public void labelSet(string controlName, bool blnVisible, string
>lblTitle)
> {
> Label objLabel;
> objLabel = (Label)this.FindControl(controlName);
> if (blnVisible)
> objLabel.Text = lblTitle;
> else
> objLabel.Visible = false;
> }
>>
>>
>Thanks,
>Robert
>>
>>------=_NextPart_000_007B_01C6A12A.759D9DC0
>>Content-Type: text/html; charset=iso-8859-1
>>Content-Transfer-Encoding: quoted-printable
>>X-Google-AttachSize: 11079
>>>
>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>><HTML><HEAD>
>><META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
>><META content="MSHTML 6.00.5346.5" name=GENERATOR>
>><STYLE></STYLE>
>></HEAD>
>><BODY>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2>First add the user
>>control
>>to the page declaration</FONT></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT> </DIV>
>><DIV><FONT face="Courier New" color=#000080 size=2><</FONT><A
>>href='mailto:%@Register Tagname="usercontrol" Tagprefix="usa"
>>src="~/controls/usercontrol.ascx"%'><FONT
>>face="Courier New" color=#000080 size=2>%@Register Tagname="usercontrol"
>>Tagprefix="usa" src="~/controls/usercontrol.ascx"%</FONT></A><FONT
>>face="Courier New" color=#000080 size=2>></FONT></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT> </DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2>then put the user
>>control in
>>the repeater</FONT></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT> </DIV>
>><DIV><asp:Repeater id=Repeater1 OnItemDataBound="processList"
>>runat="server"><ITEMTEMPLATE><?xml:namespace prefix = usa
>>/><usa:usercontrol
>>id=uscControl runat="Server"><FONT face="Courier New" color=#000080
>>size=2> <asp:Repeater id="Repeater1" runat="server"
>><STRONG>OnItemDataBound="processList"</STRONG>><BR> <ItemTemplate& gt;<STRONG><usa:usercontrol
>>runat="Server" id="uscControl"
>>/></STRONG></ItemTemplate><BR> </asp:Repeater></FONT></usa:usercontrol></ITEMTEMPLATE></asp:Repeater></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT> </DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2>then in the
>>codebehind</FONT></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT> </DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2><FONT size=2>
>><P></FONT><FONT face="Courier New"><FONT color=#0000ff
>>size=2>Private</FONT><FONT size=2</FONT><FONT color=#0000ff
>>size=2>Sub</FONT><FONT size=2processList(</FONT><FONT color=#0000ff
>>size=2>ByVal</FONT><FONT size=2sender </FONT><FONT color=#0000ff
>>size=2>As</FONT><FONT size=2</FONT><FONT color=#0000ff
>>size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff
>>size=2>ByVal</FONT><FONT size=2e </FONT><FONT color=#0000ff
>>size=2>As</FONT></FONT><FONT size=2><FONT face="Courier New">
>>System.Web.UI.WebControls.RepeaterItemEventArgs) </FONT></P>
>><P></FONT><FONT face="Courier New"><FONT color=#0000ff
>>size=2>
>>If</FONT><FONT size=2e.Item.ItemType = ListItemType.Item </FONT><FONT
>>color=#0000ff size=2>Or</FONT><FONT size=2e.Item.ItemType =
>>ListItemType.AlternatingItem </FONT><FONT color=#0000ff
>>size=2>Then</P></FONT></FONT><FONT size=2>
>><P></FONT><FONT face="Courier New"><FONT color=#0000ff
>>size=2>
>> Dim</FONT><FONT size=2usc </FONT><FONT
>>color=#0000ff
>>size=2>As</FONT><FONT size=2your_control =
>>e.Item.FindControl("uscControl")</FONT></FONT></P>
>><P><FONT face="Courier New" color=#008000 size=2>
>> 'now you can access all of the public properties and
>>methods
>>of the usercontrol, for example</FONT></P>
>><P><FONT face="Courier New" size=2>
>>usc.LabelSet("test",true,"test1")</FONT></P>
>><P><FONT size=2><FONT face="Courier New"
>>color=#008000> 'and so
>>on</FONT></P>
>><P></FONT><FONT face="Courier New"><FONT color=#0000ff
>>size=2>
>>End</FONT><FONT size=2</FONT><FONT color=#0000ff
>>size=2>If</P></FONT></FONT><FONT size=2>
>><P></FONT><FONT face="Courier New"><FONT color=#0000ff
>>size=2>End</FONT><FONT
>>size=2</FONT><FONT color=#0000ff
>>size=2>Sub</P></FONT></FONT></FONT></DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2></FONT><FONT
>>face="Trebuchet MS" color=#000080 size=2></FONT><BR><FONT
>>face="Trebuchet MS"
>>color=#000080 size=2>-- <BR>David Lozzi<BR></FONT><A
>>href="mailto:dlozzi@(remove)delphi-ts.com"><FONT face="Trebuchet MS"
>>color=#000080 size=2>dlozzi@(remove)delphi-ts.com</FONT></A><BR><A
>>href="http://www.delphi-ts.com"><FONT face="Trebuchet MS" color=#000080
>>size=2>www.delphi-ts.com</FONT></A></DIV>
>><DIV> </DIV>
>><DIV><FONT face="Trebuchet MS" color=#000080 size=2>"fernandezr"
>><</FONT><A
>>href="mailto:robert.fernandez@gmail.com"><FONT face="Trebuchet MS"
>>color=#000080
>>size=2>robert.fernandez@gmail.com</FONT></A><FONT face="Trebuchet MS"
>>color=#000080 size=2>> wrote in message </FONT><A
>>href="news:1152221976.111980.264830@s26g2000cwa. googlegroups.com"><FONT
>>face="Trebuchet MS" color=#000080
>>size=2>news:1152221976.111980.264830@s26g2000cwa .googlegroups.com</FONT></A><FONT
>>face="Trebuchet MS" color=#000080 size=2>...</FONT></DIV><FONT
>>face="Trebuchet MS" color=#000080 size=2>>I would like to use a user
>>control
>>as a template inside a repeater.<BR>> Some of the fields in the
>>control
>>should be hidden depending on whether<BR>> or not there is
>>data. I'm
>>still a ASP .Net newbie so the way I'm going<BR>> about doing this
>>might be a
>>little off. I'd appreciate some help.<BR>> <BR>> Below is
>>the code I
>>have thus far but I'm not sure how to reference the<BR>> user control
>>within
>>the foreach loop.<BR>> <BR>> <asp:Panel
>>ID="pnlRosterProfile"
>>runat="Server" /><BR>> <BR>> <asp:Repeater
>>ID="rptRoster"
>>runat="Server" ><BR>>
>><ItemTemplate><BR>>
>></ItemTemplate><BR>> </asp:Repeater><BR>>
>><BR>> Code
>>behind:<BR>> <BR>> &nbs p;
>>DataSet DS =
>>SQLRoutines.GetProfiles(strUID, strCCYYS,<BR>>
>>strRosterType);<BR>> & nbsp;
>>DataRow[]
>>foundRows =
>>DS.Tables[0].Select();<BR>> &n bsp;
>>foreach
>>(DataRow dr in
>>foundRows)<BR>>
>>{<BR>> <BR>> &nbs p; [User
>>control
>>here?]<BR>> &nbs p; }<BR>>
>><BR>>
>><BR>>
>><BR>> -------------------------------------------------<BR>> User
>>control:<BR>> <BR>> <%@ Control Language="C#"
>>AutoEventWireup="true"<BR>> CodeFile="ucProfile.ascx.cs"
>>Inherits="controls_ucRosterProfile" %><BR>>
>><BR>> <asp:Panel
>>ID="pnlProfile"
>>runat="Server"><BR>> &nbs p;
>><asp:Table ID="tblProfile"
>>runat="Server"><BR>> &nbs p;
>><asp:TableRow><BR>> &n bsp; &nbs p;
>><asp:TableCell><BR>> & nbsp; &nb sp;
>><asp:Image ID="imgPhoto" runat="Server"
>>/><BR>> &n bsp;
>></asp:TableCell><BR>> & nbsp; &nb sp;
>><asp:TableCell><BR>> & nbsp; &nb sp;
>><asp:Label ID="lblNameDesc" runat="Server"<BR>> Font-Bold="true"
>>Text="Name"
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblName" runat="Server" Text=""
>>/><BR>> &n bsp; &nbs p;
>><br
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblEmailDesc" runat="Server"<BR>> Font-Bold="true"
>>Text="Email"
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblEmail" runat="Server" Text=""
>>/><BR>> &n bsp; &nbs p;
>><br
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblEmployerDesc" runat="Server"<BR>>
>>Font-Bold="true"
>>Text="Employer"
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblEmployer" runat="Server" Text=""
>>/><BR>> &n bsp; &nbs p;
>><br
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblJobTitleDesc" runat="Server"<BR>>
>>Font-Bold="true"
>>Text="Name"
>>/><BR>> &n bsp; &nbs p;
>><asp:Label ID="lblJobTitle" runat="Server" Text=""
>>/><BR>> &n bsp; &nbs p;
>><br /><BR>>
>><BR>> &nbs p;
>></asp:TableCell><BR>> & nbsp;
>></asp:TableRow><BR>> &n bsp;
>></asp:Table><BR>>   ;
>></asp:Panel><BR>> <BR>> <BR>> user control code
>>behind:<BR>>
>><BR>> public void labelSet(string controlName, bool
>>blnVisible, string<BR>> lblTitle)<BR>>
>>{<BR>> &nb sp; Label
>>objLabel;<BR>> & nbsp; objLabel =
>>(Label)this.FindControl(controlName);<BR>>&nb sp;
>>if
>>(blnVisible)<BR>> &nbs p;
>>objLabel.Text =
>>lblTitle;<BR>> & nbsp;
>>else<BR>>
>>objLabel.Visible = false;
>><BR>> }<BR>>
>><BR>> <BR>> Thanks,<BR>> Robert<BR>></FONT></BODY></HTML>
>>>
>>------=_NextPart_000_007B_01C6A12A.759D9DC0--