By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,357 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,357 IT Pros & Developers. It's quick & easy.

Using FindControl Method with PagerTemplate

P: n/a
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("Page IndicatorLabel"); 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
Aug 5 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

HI.
You can locate the control
by using the method BottomPagerRow..FindControl of gridview.
Regards!
Ravi Kanth

<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");

*ADD FOLLOWINGF LINE HERE -----
LABEL PAGEINDICATOR=(LABEL)
DETAILSVIEW1.BOTTOMPAGERROW.FINDCONTROL(\"PAGEINDI CATORLABEL\");*
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
--
ravikanth
------------------------------------------------------------------------
ravikanth's Profile: http://www.hightechtalks.com/m25
View this thread: http://www.hightechtalks.com/t2206638

Aug 9 '05 #2

P: n/a
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("Pa geIndicatorLabel");

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

<%= Clinton Gallagher

"ravikanth" <ra**************@no-mx.forums.yourdomain.com.au> wrote in
message news:ra**************@no-mx.forums.yourdomain.com.au...

HI.
You can locate the control
by using the method BottomPagerRow..FindControl of gridview.
Regards!
Ravi Kanth

<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");

*ADD FOLLOWINGF LINE HERE -----
LABEL PAGEINDICATOR=(LABEL)
DETAILSVIEW1.BOTTOMPAGERROW.FINDCONTROL(\"PAGEINDI CATORLABEL\");*
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
--
ravikanth
------------------------------------------------------------------------
ravikanth's Profile: http://www.hightechtalks.com/m25
View this thread: http://www.hightechtalks.com/t2206638

Aug 11 '05 #3

P: n/a

Hi,
For me this worked .
I had a problem label was not getting displayed...
I added following line of code....
GridView1.BottomPagerRow.Visible = true;

Iam using beta 2 build.Which version you are using.....

Hope this will help you.I have pasted sample code below.

Ravi

PAGECODE:[/b]:

<%@ PAGE LANGUAGE=\"C#\" AUTOEVENTWIREUP=\"TRUE\"
CODEFILE=\"DEFAULT2.ASPX.CS\" INHERITS=\"DEFAULT2\" %>

<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"HTTP://WWW.W3.ORG/TR/XHTML11/DTD/XHTML11.DTD\">

<HTML XMLNS=\"HTTP://WWW.W3.ORG/1999/XHTML\" >
<HEAD RUNAT=\"SERVER\">
<TITLE>UNTITLED PAGE</TITLE>
</HEAD>
<BODY>
<FORM ID=\"FORM1\" RUNAT=\"SERVER\">
<DIV>
<BR />
<BR />
<ASP:SQLDATASOURCE ID=\"SQLDATASOURCE1\" RUNAT=\"SERVER\"
SELECTCOMMAND=\"SELECT [EMPID], [EMPNAME], [DEPTID] FROM
[TBLEMPLOYEE]\" CONNECTIONSTRING=\"<%$
CONNECTIONSTRINGS:TESTSRCONNECTIONSTRING %>\"></ASP:SQLDATASOURCE>
<ASP:GRIDVIEW ID=\"GRIDVIEW1\" RUNAT=\"SERVER\"
ALLOWSORTING=\"TRUE\"
AUTOGENERATECOLUMNS=\"FALSE\" DATAKEYNAMES=\"EMPID\"
DATASOURCEID=\"SQLDATASOURCE1\" HEIGHT=\"156PX\" WIDTH=\"632PX\"
ALLOWPAGING=\"TRUE\">
<PAGERSETTINGS POSITION=\"BOTTOM\" />
<PAGERTEMPLATE>
<ASP:LABEL ID=\"PAGEINDICATORLABEL\" RUNAT=SERVER
TEXT=\"TRYING OUT\"></ASP:LABEL></BR>
</PAGERTEMPLATE>
<COLUMNS>
<ASP:BOUNDFIELD DATAFIELD=\"EMPID\"
HEADERTEXT=\"EMPID\" INSERTVISIBLE=\"FALSE\" READONLY=\"TRUE\"
SORTEXPRESSION=\"EMPID\" />
<ASP:BOUNDFIELD DATAFIELD=\"EMPNAME\"
HEADERTEXT=\"EMPNAME\" SORTEXPRESSION=\"EMPNAME\" />
<ASP:BOUNDFIELD DATAFIELD=\"DEPTID\"
HEADERTEXT=\"DEPTID\" SORTEXPRESSION=\"DEPTID\" />
</COLUMNS>
<FOOTERSTYLE BACKCOLOR=\"#CCCC99\" FORECOLOR=\"BLACK\"
/>
<PAGERSTYLE BACKCOLOR=\"WHITE\" FORECOLOR=\"BLACK\"
HORIZONTALALIGN=\"LEFT\" />
<SELECTEDROWSTYLE BACKCOLOR=\"#CC3333\"
FONT-BOLD=\"TRUE\" FORECOLOR=\"WHITE\" />
<HEADERSTYLE BACKCOLOR=\"#333333\" FONT-BOLD=\"TRUE\"
FORECOLOR=\"WHITE\" />
</ASP:GRIDVIEW>
&NBSP;&NBSP;

</DIV>
</FORM>
</BODY>
</HTML>

[b]
CODE BEHIDN CODE:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.WebControls.Label PageIndicatorLabel =
(System.Web.UI.WebControls.Label)GridView1.BottomP agerRow.FindControl("PageIndicatorLabel");
if(PageIndicatorLabel !=null)
{
Response.Write("<p><b> Label control found</base></p>");
PageIndicatorLabel.Text="Label Control found";
GridView1.BottomPagerRow.Visible = true;
//PageIndicatorLabel.Visible = true;

}
else{
Response.Write("<p><b> Label control not
found</base></p>");
PageIndicatorLabel.Text="Label Control not found";
}
}
}
--
ravikanth
------------------------------------------------------------------------
ravikanth's Profile: http://www.hightechtalks.com/m25
View this thread: http://www.hightechtalks.com/t2206638

Aug 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.