473,218 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 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 1838
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Kaminski [MVP] | last post by:
On my code behind page, how can I reference a Label control that's included in a Repeater? In other words, given: <asp:Repeater id="Repeater1" runat="server"> <HeaderTemplate> <table> <tr>...
3
by: WebMatrix | last post by:
I am struggling with implementing somewhat complicated UI web-control. I explored Repeater, but I am not sure if it's the best way to go. I am leaning towards writing my own custom control and...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
3
by: sck10 | last post by:
Hello, How do you reference a label inside a repeater? I tried the following and got the error: Object reference not set to an instance of an object. ...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
2
by: AC [MVP MOSS] | last post by:
I have a repeater with a header, footer, and item template. The item template is the only one with server controls (hyperlinks, labels, and a nested repeater). Within the top repeater, I'm handling...
1
by: Doogie | last post by:
Hi, I have been trying to get a checkbox added to a repeater control of mine and then try to access events of the repeater control when a user clicks the checkbox. At first, since the control is...
3
by: Emma Middlebrook | last post by:
Hi there, I've been trying to implement a repeater control in an ASP.NET 2 page but I can't seem to get the layout exactly how I want and I'm not sure if it's something that I am doing wrong or...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.