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 7178105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:51:11+00:00 2026-05-28T16:51:11+00:00

I have controls that are named in numeric sequence. I’d like to assign values

  • 0

I have controls that are named in numeric sequence.
I’d like to assign values those controls using loop.
The code below is the way i’m currently using.

txtSalesInvoiceForm_Qty1.Text = (salesInvoice.ItemQty1 == 0) ? string.Empty : salesInvoice.ItemQty1.ToString();
txtSalesInvoiceForm_Qty2.Text = (salesInvoice.ItemQty2 == 0) ? string.Empty : salesInvoice.ItemQty2.ToString();
txtSalesInvoiceForm_Qty3.Text = (salesInvoice.ItemQty3 == 0) ? string.Empty : salesInvoice.ItemQty3.ToString();
txtSalesInvoiceForm_Qty4.Text = (salesInvoice.ItemQty4 == 0) ? string.Empty : salesInvoice.ItemQty4.ToString();
txtSalesInvoiceForm_Qty5.Text = (salesInvoice.ItemQty5 == 0) ? string.Empty : salesInvoice.ItemQty5.ToString();
txtSalesInvoiceForm_Unit1.Text = salesInvoice.Unit1;
txtSalesInvoiceForm_Unit2.Text = salesInvoice.Unit2;
txtSalesInvoiceForm_Unit3.Text = salesInvoice.Unit3;
txtSalesInvoiceForm_Unit4.Text = salesInvoice.Unit4;
txtSalesInvoiceForm_Unit5.Text = salesInvoice.Unit5;
txtSalesInvoiceForm_Particulars1.Text = salesInvoice.Particulars1;
txtSalesInvoiceForm_Particulars2.Text = salesInvoice.Particulars2;
txtSalesInvoiceForm_Particulars3.Text = salesInvoice.Particulars3;
txtSalesInvoiceForm_Particulars4.Text = salesInvoice.Particulars4;
txtSalesInvoiceForm_Particulars5.Text = salesInvoice.Particulars5;

Is there any way something like this?

int index = 1;
foreach (SalesInvoiceItem item in salesInvoice.SalesInvoiceItems)
{
    (txtSalesInvoiceForm_Qty + index.ToString()).Text = Value;
    indexer++                        
}
  • 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-28T16:51:13+00:00Added an answer on May 28, 2026 at 4:51 pm
    Control parent = this.pnlParent; // this must be the immediate parent control
    
    int index = 1;
    foreach (SalesInvoiceItem item in salesInvoice.SalesInvoiceItems)
    {
        TextBox tb = parent.FindControl( "txtSalesInvoiceForm_Qty" + index++ ) as TextBox;
        tb.Text = Value;       
    }
    

    The key is FindControl(), which searches the immediate children of a parent. Personally I think this is sloppy code in most cases.

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

Sidebar

Related Questions

I'm using VB 2010 Express. I have a loop that calls a function named
I have two TDBLookupComboBox controls that I'd like to connect to the same dataset,
To dynamically fill DropDown controls on my HTML Form, I have written code that
I have a gridview that gets created in codebehind. In the below code, I
I have two custom controls that are analogous to a node and the control
I have a few controls that inherit from ASP.NET buttons and use onserverclick .
I have some user controls that I'm loading in SharePoint and I would prefer
I have several server controls that implement the IValidator interface. As such, they have
I'm creating a login page. I want to create ASP.NET TextBox controls that have
I have a list of controls that I am displaying via a WrapPanel and

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.