473,692 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;
PageIndicatorLa bel..

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

// HTML SOURCE
<PagerTemplat e>
....
<asp:Label ID="Label8" runat="server" Width="200px"></asp:Label>
<asp:Label ID="PageIndicat orLabel" runat="server" Width="200px"></asp:Label>
....
</PagerTemplate>

// PAGE_LOAD CODE BEHIND
string recordX = DetailsView1.Da taItemIndex.ToS tring( );
string recordY = DetailsView1.Pa geCount.ToStrin g( );

Control pageIndicator = FindControl("Pa geIndicatorLabe l");

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

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

I've tried
Page.FindContro l("DetailsView1 ").FindControl( "PageIndicatorL abel"); 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 PageIndicatorLa bel.

Where have I gone wrong?

<%= Clinton Gallagher
Aug 5 '05 #1
3 8507

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

<PagerTemplat e>
....
<asp:Label ID="Label8" runat="server" Width="200px"></asp:Label>
<asp:Label ID="PageIndicat orLabel" runat="server"
Width="200px"></asp:Label>
....
</PagerTemplate>

// PAGE_LOAD CODE BEHIND
string recordX = DetailsView1.Da taItemIndex.ToS tring( );
string recordY = DetailsView1.Pa geCount.ToStrin g( );

Control pageIndicator = FindControl("Pa geIndicatorLabe l");

*ADD FOLLOWINGF LINE HERE -----
LABEL PAGEINDICATOR=( LABEL)
DETAILSVIEW1.BO TTOMPAGERROW.FI NDCONTROL(\"PAG EINDICATORLABEL \");*
if(pageIndicato r != null)
{
// this label's properties can not be set
pageIndicator.T ext = "if.pageIndicat or.Text";
}
else
{
// this label's properties can not be set
pageIndicator.T ext = "if.pageIndicat or.Text";
}

Error:
System.Web.UI.C ontrol 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)DetailsV iew1.BottomPage rRow.FindContro l("PageIndicato rLabel");

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

<%= Clinton Gallagher

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

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

<PagerTemplat e>
...
<asp:Label ID="Label8" runat="server" Width="200px"></asp:Label>
<asp:Label ID="PageIndicat orLabel" runat="server"
Width="200px"></asp:Label>
...
</PagerTemplate>

// PAGE_LOAD CODE BEHIND
string recordX = DetailsView1.Da taItemIndex.ToS tring( );
string recordY = DetailsView1.Pa geCount.ToStrin g( );

Control pageIndicator = FindControl("Pa geIndicatorLabe l");

*ADD FOLLOWINGF LINE HERE -----
LABEL PAGEINDICATOR=( LABEL)
DETAILSVIEW1.BO TTOMPAGERROW.FI NDCONTROL(\"PAG EINDICATORLABEL \");*
if(pageIndicato r != null)
{
// this label's properties can not be set
pageIndicator.T ext = "if.pageIndicat or.Text";
}
else
{
// this label's properties can not be set
pageIndicator.T ext = "if.pageIndicat or.Text";
}

Error:
System.Web.UI.C ontrol 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.Botto mPagerRow.Visib le = 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=\"DEFA ULT2.ASPX.CS\" INHERITS=\"DEFA ULT2\" %>

<!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>UNTITL ED PAGE</TITLE>
</HEAD>
<BODY>
<FORM ID=\"FORM1\" RUNAT=\"SERVER\ ">
<DIV>
<BR />
<BR />
<ASP:SQLDATASOU RCE ID=\"SQLDATASOU RCE1\" RUNAT=\"SERVER\ "
SELECTCOMMAND=\ "SELECT [EMPID], [EMPNAME], [DEPTID] FROM
[TBLEMPLOYEE]\" CONNECTIONSTRIN G=\"<%$
CONNECTIONSTRIN GS:TESTSRCONNEC TIONSTRING %>\"></ASP:SQLDATASOUR CE>
<ASP:GRIDVIEW ID=\"GRIDVIEW1\ " RUNAT=\"SERVER\ "
ALLOWSORTING=\" TRUE\"
AUTOGENERATECOL UMNS=\"FALSE\" DATAKEYNAMES=\" EMPID\"
DATASOURCEID=\" SQLDATASOURCE1\ " HEIGHT=\"156PX\ " WIDTH=\"632PX\"
ALLOWPAGING=\"T RUE\">
<PAGERSETTING S POSITION=\"BOTT OM\" />
<PAGERTEMPLAT E>
<ASP:LABEL ID=\"PAGEINDICA TORLABEL\" RUNAT=SERVER
TEXT=\"TRYING OUT\"></ASP:LABEL></BR>
</PAGERTEMPLATE>
<COLUMNS>
<ASP:BOUNDFIE LD DATAFIELD=\"EMP ID\"
HEADERTEXT=\"EM PID\" INSERTVISIBLE=\ "FALSE\" READONLY=\"TRUE \"
SORTEXPRESSION= \"EMPID\" />
<ASP:BOUNDFIE LD DATAFIELD=\"EMP NAME\"
HEADERTEXT=\"EM PNAME\" SORTEXPRESSION= \"EMPNAME\" />
<ASP:BOUNDFIE LD DATAFIELD=\"DEP TID\"
HEADERTEXT=\"DE PTID\" SORTEXPRESSION= \"DEPTID\" />
</COLUMNS>
<FOOTERSTYLE BACKCOLOR=\"#CC CC99\" FORECOLOR=\"BLA CK\"
/>
<PAGERSTYLE BACKCOLOR=\"WHI TE\" FORECOLOR=\"BLA CK\"
HORIZONTALALIGN =\"LEFT\" />
<SELECTEDROWSTY LE BACKCOLOR=\"#CC 3333\"
FONT-BOLD=\"TRUE\" FORECOLOR=\"WHI TE\" />
<HEADERSTYLE BACKCOLOR=\"#33 3333\" FONT-BOLD=\"TRUE\"
FORECOLOR=\"WHI TE\" />
</ASP:GRIDVIEW>
&NBSP;&NBSP;

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

[b]
CODE BEHIDN CODE:

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

public partial class Default2 : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
System.Web.UI.W ebControls.Labe l PageIndicatorLa bel =
(System.Web.UI. WebControls.Lab el)GridView1.Bo ttomPagerRow.Fi ndControl("Page IndicatorLabel" );
if(PageIndicato rLabel !=null)
{
Response.Write( "<p><b> Label control found</base></p>");
PageIndicatorLa bel.Text="Label Control found";
GridView1.Botto mPagerRow.Visib le = true;
//PageIndicatorLa bel.Visible = true;

}
else{
Response.Write( "<p><b> Label control not
found</base></p>");
PageIndicatorLa bel.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
2801
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 one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created on the page. So I need multiple forms on a asp.net page(doesn't everyone). I purchased the...
6
1630
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 textbox name and then pass it to the FindControl() method to return the value. This works great when I use the method in the code-behind for the exact page that I want to use it on. However, I'd like to use this same method on other pages throughout my...
14
5792
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 SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
3
1202
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 DetailsView control which supports a PagingTemplate. Somewhere I grabbed some declarations for a PagerTemplate to display paging as: <<First < Prev Next> Last>>
0
1655
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" runat="server"> <PagerTemplate> <font class="smalltext">Page:</font> <asp:Label ID="lblCurrentPage" runat="server"
3
15716
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
6564
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server" OnClick="btnAddMember_Click">Add...</asp:LinkButton> <asp:TextBox ID="txtAddMember" runat="server"></asp:TextBox>
0
1007
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: CType(Me.FormViewID.FindControl("PagerTemplateControlID"), LinkButton) However, this gives me the following error:
0
2266
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 arrow for the last page. The dropdownlist function is okay, but I m blocked with the arrows
0
8611
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8547
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7639
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6462
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4564
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.