472,779 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 8438

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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.