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

  • Home
  • SEARCH
  • 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 6968745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:29:30+00:00 2026-05-27T16:29:30+00:00

On a Visual Web Part pageLoad event (c#) I am calling a REST API

  • 0

On a Visual Web Part pageLoad event (c#) I am calling a REST API which returns results in XML. I want to dynamically set labels in a table depending on the number of results returned. As the XML is parsed node 1 will set labels 1, node 2 labels 2 etc.

In the example code below I want to set the value of Label1_1.Text on iteration 1, Label2_1.Text on iteration 2, Label3_1.Text on iteration 3 and so on.

How can this be achieved?

foreach (XmlNode elem in nodes)
{
    string childOne     = elem["contact1"].InnerText.ToString();
    string childTwo     = elem["contact2"].InnerText.ToString();
    string childThree   = elem["contact3"].InnerText.ToString();
    string childFour    = elem["contact4"].InnerText.ToString();

    // I want Label1 to effectively be Labelx (x being the iteration)
    // so it is dynamic based on the number of iterations in the loop
    Label1_1.Text = childOne;
    Label1_2.Text = childTwo;
    Label1_3.Text = childThree;
    Label1_4.Text = childFour;
}
  • 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-05-27T16:29:31+00:00Added an answer on May 27, 2026 at 4:29 pm

    You will need to use the FindControl method on the containing control if you already have all of the labels as controls within the container.

    Label toUpdate = (Label)myTable.FindControl("Label1_1");
    toUpdate.Text = childOne;
    

    If the label controls don’t already exist you will need to create and add them dynamically (in which case the Id would be need to be unique).

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

Sidebar

Related Questions

I'm trying to build a visual web part for SharePoint 2010 which should connect
I have created a Hello World web part. When I pressed F5 in Visual
I make a simple Visual web part and deployed it, and put it on
In SharePoint 2010 I have a visual web part that uses SP.UI.ModalDialog.showModalDialog The dialog
I am trying to build a SharePoint 2007 web part in Visual Studio. This
I have a very simple web part. I have a single grid view, which
I created a new Visual Web Part in VS 2010 (using Sharepoint Server 2010),
weird issue with visual studio 2010, right now i'm debugging a web application (which
I'm developing a SP 2010 Visual Web Part that needs to load some data
I am using sharepoint 2010 and developing a visual web part. I had javascript

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.