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.RepeaterItemEventArgs)
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
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

anel 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

anel 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

anel>
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><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=2> processList(</FONT><FONT color=#0000ff
size=2>ByVal</FONT><FONT size=2> sender </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=2> e </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=2> e.Item.ItemType = ListItemType.Item </FONT><FONT
color=#0000ff size=2>Or</FONT><FONT size=2> e.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=2> usc </FONT><FONT color=#0000ff
size=2>As</FONT><FONT size=2> your_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:
[email protected]"><FONT face="Trebuchet MS"
color=#000080
size=2>
[email protected]</FONT></A><FONT face="Trebuchet MS"
color=#000080 size=2>> wrote in message </FONT><A
href="face="Trebuchet MS" color=#000080
size=2>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

anel
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>>
DataSet DS =
SQLRoutines.GetProfiles(strUID, strCCYYS,<BR>>
strRosterType);<BR>>
DataRow[]
foundRows =
DS.Tables[0].Select();<BR>>
foreach
(DataRow dr in
foundRows)<BR>>
{<BR>> <BR>> [User
control
here?]<BR>> }<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

anel
ID="pnlProfile"
runat="Server"><BR>>
<asp:Table ID="tblProfile"
runat="Server"><BR>>
<asp:TableRow><BR>>
<asp:TableCell><BR>>
<asp:Image ID="imgPhoto" runat="Server"
/><BR>>
</asp:TableCell><BR>>
<asp:TableCell><BR>>
<asp:Label ID="lblNameDesc" runat="Server"<BR>> Font-Bold="true"
Text="Name"
/><BR>>
<asp:Label ID="lblName" runat="Server" Text=""
/><BR>>
<br
/><BR>>
<asp:Label ID="lblEmailDesc" runat="Server"<BR>> Font-Bold="true"
Text="Email"
/><BR>>
<asp:Label ID="lblEmail" runat="Server" Text=""
/><BR>>
<br
/><BR>>
<asp:Label ID="lblEmployerDesc" runat="Server"<BR>>
Font-Bold="true"
Text="Employer"
/><BR>>
<asp:Label ID="lblEmployer" runat="Server" Text=""
/><BR>>
<br
/><BR>>
<asp:Label ID="lblJobTitleDesc" runat="Server"<BR>>
Font-Bold="true"
Text="Name"
/><BR>>
<asp:Label ID="lblJobTitle" runat="Server" Text=""
/><BR>>
<br /><BR>>
<BR>>
</asp:TableCell><BR>>
</asp:TableRow><BR>>
</asp:Table><BR>>
</asp

anel><BR>> <BR>> <BR>> user control code
behind:<BR>>
<BR>> public void labelSet(string controlName, bool
blnVisible, string<BR>> lblTitle)<BR>>
{<BR>> Label
objLabel;<BR>> objLabel =
(Label)this.FindControl(controlName);<BR>>
if
(blnVisible)<BR>>
objLabel.Text =
lblTitle;<BR>>
else<BR>>
objLabel.Visible = false;
<BR>> }<BR>>
<BR>> <BR>> Thanks,<BR>> Robert<BR>></FONT></BODY></HTML>
------=_NextPart_000_007B_01C6A12A.759D9DC0--