Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:23:21+00:00 2026-06-07T10:23:21+00:00

Working with a GridView in C# (ASP.NET) and I’m trying to iterate over a

  • 0

Working with a GridView in C# (ASP.NET) and I’m trying to iterate over a single row. Normally it wouldn’t be too difficult if I could extract the text in each cell:

string text = SecGrpGridView.Rows[0].Cells[i].Text;

However, some of the fields in my row contain Labels and I believe the only way to extract the value is using FindControl() and casting it to a Label:

Label myLabel = (Label)SecGrpGridView.Rows[0].Cells[i].FindControl("Label5");
string text = myLabel.Text;

As you can see, the second example I needed to know the ID of my label so it makes it difficult to iterate over unless I have sequentially named labels. I know that a future need will be to add more columns to my row so I’m looking for a way to iterate over this row without having to name the labels sequentially. (ie ‘Label1’, ‘Label2’, ‘Label3’) Is there a better way to go about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:23:24+00:00Added an answer on June 7, 2026 at 10:23 am

    You can gather all the Labels in GridView by using the following code

    public static List<Label> FindLabelRecursive(Control root)
    {
        List<Label> labels = new List<Label>();
        if (root is Label)
        {
            labels.Add(root as Label);
            return labels;
        }
    
        foreach(Control c in root.Controls)
        {
            if (c is Label)
            {
                labels.Add(c);
            }
            else
            {
                List<Label> childLabels = FindLabelRecursive(c);
                labels.AddRange(childLabels);
            }
        }
    
        return labels;
    }
    

    Then do you processing based on the labels returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a GridView in Asp.Net. When initially a the Page Loads,
I'm working on an ASP.NET Web Project with some AJAX magic. As my GridView
i have a gridview i am working on VS2008 ASP.Net forms Currently, my update
I am working with asp.net 2.0 project. I have a gridview in one of
I am working on an ASP.Net website and have a GridView displaying some data,in
Working on setting up a SqlDataSource connecting MySQL database to a ASP .NET GridView.
I'm trying to sort a list of entities using a GridView in ASP.NET, but
I'm working on an ASP.Net page containing a GridView, which is populated with customer
I am working on Gridview in ASP.NET(C#) and have cells that need to have
I'm working with an ASP.net 2.0 GridView control that is bound to the results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.