Using FindControl Method with PagerTemplate

C

clintonG

Briefly stated, my problem is accessing and 'setting' properties of a label
control declared in the template of another control noting that the other
control is an instance of the beta 2 DetailsView control which supports a
PagingTemplate.

Somewhere I grabbed some declarations for a PagerTemplate to display paging
as:

<<First < Prev [Record 0 of 5] Next> Last>>

I observed that Record 0 was reported as zero when the DataView was actually
displaying a record. So I thought I'd write some code to normalize the
reported values for users not familiar with zero based data structures.

I attempted to being to normalize by declaring a label in the PagerTemplate;
PageIndicatorLabel..

I can't set the text property of the PageIndicatorLabel control when using
PageIndicatorLabel.Text which make me go "huh?"

// HTML SOURCE
<PagerTemplate>
....
<asp:Label ID="Label8" runat="server" Width="200px"></asp:Label>
<asp:Label ID="PageIndicatorLabel" runat="server" Width="200px"></asp:Label>
....
</PagerTemplate>

// PAGE_LOAD CODE BEHIND
string recordX = DetailsView1.DataItemIndex.ToString( );
string recordY = DetailsView1.PageCount.ToString( );

Control pageIndicator = FindControl("PageIndicatorLabel");

if(pageIndicator != null)
{
// this label's properties can not be set
pageIndicator.Text = "if.pageIndicator.Text";
}
else
{
// this label's properties can not be set
pageIndicator.Text = "if.pageIndicator.Text";
}

Error:
System.Web.UI.Control does not contain a definition for Text

I've tried
Page.FindControl("DetailsView1").FindControl("PageIndicatorLabel"); but
still generate the same error. I'm not initializing the pageIndicator object
correctly or I am misusing the FindControl method because I can not set the
text property for the PageIndicatorLabel.

Where have I gone wrong?

<%= Clinton Gallagher
 
C

clintonG

Thank you for your comments but I've tried your suggestion (and 3-4 other
methods) already and still no results...

Label pageIndicator =
(Label)DetailsView1.BottomPagerRow.FindControl("PageIndicatorLabel");

if(pageIndicator != null)
{
Response.Write("<p /><b>Label Control Found</b>");
pageIndicator.Text = "Label Control Found";
}

<%= Clinton Gallagher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top