Solved

Findcontrol Within a Gridview Footer template

Posted on 2006-11-29
2
1,262 Views
Last Modified: 2008-01-09
Ah! Mega Urgent!

I am trying to locate a Label within a footer template of a Gridview and am using the following code to do so but get the error 'Object reference not set to an instance of an object'...

Code-Behind Code within an button OnClick event:

Dim lblRec As Label = GridView1.FindControl("lblRecTonT")


Could anyone kindly advise what I could be doing wrong?

Many thanks

Rit
0
Comment
Question by:rito1
2 Comments
 
LVL 1

Author Comment

by:rito1
ID: 18038365
I found the answer, just in case anyone is in the same position as me.. ever :-)

Dim lblRec As Label = GridView1.FooterRow.FindControl("lblRecTonT") - in needs the 'FooterRow'
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 18039146
Here is some C# code which should be easy to convert. Pass in the id "lblRecTonT" and the control collection Page.controls or GridView1.Controls. This is guaranteed to work if the ID exists.

public static System.Web.UI.Control FindControl(string controlId, System.Web.UI.ControlCollection controls)
            {
                  for (int counter = 0; counter < controls.Count; ++counter) // loop through each control in the control collection
                  {
                        if (controls[counter].ID == controlId) //see if the current control is a match
                        {
                              return controls[counter];
                        }
                        else if (controls[counter].Controls.Count > 0) // check the child controls
                        {
                              System.Web.UI.Control FoundControl = FindControl(controlId, controls[counter].Controls); // recursive call to check child controls

                              if (FoundControl != null) // control found in child's controls
                              {
                                    return FoundControl;
                              }
                        }
                  }

                  return null;
            }
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question