Solved

Findcontrol Within a Gridview Footer template

Posted on 2006-11-29
2
1,234 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now