473,320 Members | 1,828 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,320 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 1840
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.