473,394 Members | 1,706 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,394 software developers and data experts.

Using FindControl Method with PagerTemplate

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
3 8487

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
6
by: D Sheldon | last post by:
I have created a method that accepts a string value (representing the name of a textbox) and then returns the value. Because the name of the textbox can change, I first build a string with the...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
3
by: clintonG | last post by:
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...
0
by: Stuart Shay | last post by:
Hello All I am working on creating a generic theme for my GridView Controls. In My Skin File I have something like this. <asp:GridView SkinId="CustomPager" CssClass="gridView"...
3
by: Dabbler | last post by:
When I try and edit the PagerTemplate it erases the default paging controls. Is there a way to add a link control to this region while still keeping the default paging controls? Thanks.
2
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server"...
0
by: Nathan Sokalski | last post by:
I am using a FormView control, and want to access the controls I have created in the PagerTemplate. Right now, I am doing this using the following method: ...
0
by: Stan SR | last post by:
Hi, I need to customize a pargertemplate with these items a arrow to go back to the 1rst page a arrow for the previous page a dropdownlist with the page indexes a arrow for the new page a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.