471,595 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Reference control in Repeater Control

Hello,

I am using the following Repeater control. How do I reference the label
"lblCurrentYr"?

Thanks, sck10
<asp:Repeater id="rptCustomerRevenue" runat="server">
<HeaderTemplate>
<table class="tblOutline" style="width:100%" border="1px">
<tr>
<th style="width:37%;">Service</th>
<th style="width:12%;"><asp:Label ID="lblCurrentYr" runat="server"
/></th>
<th style="width:11%;"><asp:Label ID="lblYearMinus01" runat="server"
/></th>
<th style="width:15%;"><asp:Label ID="lblYearMinus02" runat="server"
/></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:37%; text-align:left;"><%#Eval("Service")%></td>
<td style="width:12%; text-align:right;"><%#Eval("CurrentYrMinus00",
"{0:C0}")%></td>
<td style="width:11%; text-align:right;"><%#Eval("CurrentYrMinus01",
"{0:C0}")%></td>
<td style="width:15%; text-align:right;"><%#Eval("CurrentYrMinus02",
"{0:C0}")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Jan 4 '07 #1
4 1776
Handle ItemCreated or ItemDataBound event. Use e.Item.ItemType to tell the
Header item. Use e.Item.FindControl("lblCurrentYr") to locate the label
inside the header item.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"sck10" <sc***@online.nospamwrote in message
news:ua**************@TK2MSFTNGP04.phx.gbl...
Hello,

I am using the following Repeater control. How do I reference the label
"lblCurrentYr"?

Thanks, sck10
<asp:Repeater id="rptCustomerRevenue" runat="server">
<HeaderTemplate>
<table class="tblOutline" style="width:100%" border="1px">
<tr>
<th style="width:37%;">Service</th>
<th style="width:12%;"><asp:Label ID="lblCurrentYr" runat="server"
/></th>
<th style="width:11%;"><asp:Label ID="lblYearMinus01" runat="server"
/></th>
<th style="width:15%;"><asp:Label ID="lblYearMinus02" runat="server"
/></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:37%; text-align:left;"><%#Eval("Service")%></td>
<td style="width:12%; text-align:right;"><%#Eval("CurrentYrMinus00",
"{0:C0}")%></td>
<td style="width:11%; text-align:right;"><%#Eval("CurrentYrMinus01",
"{0:C0}")%></td>
<td style="width:15%; text-align:right;"><%#Eval("CurrentYrMinus02",
"{0:C0}")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>


Jan 4 '07 #2
Hello Steve,

For your scenario, there are two possible means:

1. Directly access the repeater header through controls collection by
index(this is not quite recommended since index is not guranteed to work
between different version). e.g.

#header row is the first childcontrol in repeater's Controls collection
====================
protected void Button1_Click(object sender, EventArgs e)
{
Label lbl = Repeater1.Controls[0].FindControl("lblCurrentYr") as
Label;

if (lbl != null)
{
lbl.Text = "new text " + DateTime.Now.Ticks;
}

}
=========================

2. As Eliyahu has mentioned, one place we can access repeater's header(or
footer)'s controls is the ItemCreated, you can get the label in header in
that event and store it into a page variable so that you can use it later.
e.g.

========in page code behind=========
public partial class Part1_repeaterpage : System.Web.UI.Page
{
Label _repeaterLabel = null;
................
protected void Button1_Click(object sender, EventArgs e)
{

Response.Write("<br/>label value: " + _repeaterLabel.Text);

}
protected void Repeater1_ItemCreated(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
Label lbl = e.Item.FindControl("lblCurrentYr") as Label;

if (lbl != null)
{
_repeaterLabel = lbl;
}
}
}
.....................
}

=============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 5 '07 #3
Thanks Eliyahu,

sck10
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uk**************@TK2MSFTNGP03.phx.gbl...
Handle ItemCreated or ItemDataBound event. Use e.Item.ItemType to tell the
Header item. Use e.Item.FindControl("lblCurrentYr") to locate the label
inside the header item.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"sck10" <sc***@online.nospamwrote in message
news:ua**************@TK2MSFTNGP04.phx.gbl...
>Hello,

I am using the following Repeater control. How do I reference the label
"lblCurrentYr"?

Thanks, sck10
<asp:Repeater id="rptCustomerRevenue" runat="server">
<HeaderTemplate>
<table class="tblOutline" style="width:100%" border="1px">
<tr>
<th style="width:37%;">Service</th>
<th style="width:12%;"><asp:Label ID="lblCurrentYr" runat="server"
/></th>
<th style="width:11%;"><asp:Label ID="lblYearMinus01" runat="server"
/></th>
<th style="width:15%;"><asp:Label ID="lblYearMinus02" runat="server"
/></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:37%; text-align:left;"><%#Eval("Service")%></td>
<td style="width:12%; text-align:right;"><%#Eval("CurrentYrMinus00",
"{0:C0}")%></td>
<td style="width:11%; text-align:right;"><%#Eval("CurrentYrMinus01",
"{0:C0}")%></td>
<td style="width:15%; text-align:right;"><%#Eval("CurrentYrMinus02",
"{0:C0}")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>



Jan 5 '07 #4
Steven,

Thanks again for your help.

Have a good one,

sck10
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:Q8**************@TK2MSFTNGHUB02.phx.gbl...
Hello Steve,

For your scenario, there are two possible means:

1. Directly access the repeater header through controls collection by
index(this is not quite recommended since index is not guranteed to work
between different version). e.g.

#header row is the first childcontrol in repeater's Controls collection
====================
protected void Button1_Click(object sender, EventArgs e)
{
Label lbl = Repeater1.Controls[0].FindControl("lblCurrentYr") as
Label;

if (lbl != null)
{
lbl.Text = "new text " + DateTime.Now.Ticks;
}

}
=========================

2. As Eliyahu has mentioned, one place we can access repeater's header(or
footer)'s controls is the ItemCreated, you can get the label in header in
that event and store it into a page variable so that you can use it later.
e.g.

========in page code behind=========
public partial class Part1_repeaterpage : System.Web.UI.Page
{
Label _repeaterLabel = null;
...............
protected void Button1_Click(object sender, EventArgs e)
{

Response.Write("<br/>label value: " + _repeaterLabel.Text);

}
protected void Repeater1_ItemCreated(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
Label lbl = e.Item.FindControl("lblCurrentYr") as Label;

if (lbl != null)
{
_repeaterLabel = lbl;
}
}
}
....................
}

=============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 5 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Tom Kaminski [MVP] | last post: by
1 post views Thread by olduncleamos | last post: by
7 posts views Thread by charliewest | last post: by
3 posts views Thread by sck10 | last post: by
3 posts views Thread by Emma Middlebrook | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.