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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:29:20+00:00 2026-06-07T06:29:20+00:00

I have 2 lists of strings and I’d like to dynamically create a grid

  • 0

I have 2 lists of strings and I’d like to dynamically create a grid of textboxes:

List<string> X = {"A", "B", "C"};
List<string> Y = {"1", "2", "3", "4"};

          A     B     C
     1   TBX   TBX   TBX
     2   TBX   TBX   TBX
     3   TBX   TBX   TBX
     4   TBX   TBX   TBX

     [Button]

When I enter data into the textboxes and click the button, I’d like to be able to iterate over these textboxes and determine the “X” and “Y” coordinates associated with each textbox.

I can probably figure out how to dynamically create this grid of textboxes, but I think I’ll run into issues when I post the data. How do I get the values from the dynamically created textboxes after a postback?

I’ll have no issue doing the iteration and actual logic but I can’t figure out how to get the data into a container so that it can be iterated. Will I have to dynamically create the textboxes again while reading the posted data? What does that look like?

  • 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-07T06:29:21+00:00Added an answer on June 7, 2026 at 6:29 am

    Here is another approach. You can have a place holder in the asp.net page. In code behind dynamically create a table with dynamic text boxes and insert it inside place holder. In this instance you have control over the ID of each textbox. On post back values entered into the text boxes will be retained (since IDs are definite you can do javascript manipulation as well)

    Here is the aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DynamicControls.aspx.cs" Inherits="Test2.DynamicControls" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:PlaceHolder ID="PHDynamicTable" runat="server"></asp:PlaceHolder>
            <asp:Button runat="server" ID="btnSubmit" Text="Submit" 
                onclick="btnSubmit_Click" />
        </div>
        </form>
    </body>
    </html>
    

    Code behind

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Test2
    {
        public partial class DynamicControls : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected override void OnPreInit(EventArgs e)
            {
                base.OnPreInit(e);
                CreateTextBoxesInTable();
            }
    
            private void CreateTextBoxesInTable()
            {
                PHDynamicTable.Controls.Clear();
    
                List<string> X = new List<string>() { "A", "B", "C" };
                List<string> Y = new List<string>() { "1", "2", "3", "4" };
    
                Table table = new Table();
                table.ID = "dynamicTable";
    
                TableRow tr;
                foreach (string y in Y)
                {
                    tr = new TableRow();
    
                    foreach (string x in X)
                    { 
                        TableCell tc = new TableCell();
    
                        TextBox textBox = new TextBox();
                        textBox.ID = "txt_" + x + y;
                        tc.Controls.Add(textBox);
    
                        tr.Cells.Add(tc);
                    }
    
                    table.Rows.Add(tr);
                }
    
                PHDynamicTable.Controls.Add(table);
            }
    
            protected void btnSubmit_Click(object sender, EventArgs e)
            {
                if (PHDynamicTable.Controls.Count > 0)
                {
                    Table dynamicTable = (Table)PHDynamicTable.FindControl("dynamicTable");
                    if (dynamicTable != null)
                    {
                        foreach (TableRow tr in dynamicTable.Rows)
                        {
                            foreach (TableCell tc in tr.Cells)
                            {
                                TextBox textBox = (TextBox)tc.Controls[0];
                                string text = textBox.Text;
                                //Do whatever you want with the control
                            }
                        }
                    }
                }
            }
        }
    }
    

    Few screen shots

    input screen with data

    enter image description here

    on postback (submit)

    enter image description here

    after submit

    enter image description here

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

Sidebar

Related Questions

I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have several lists of strings like so, from a possible list of several
If I have 2 lists of strings: List<string> firstList = new List<string>(010, 111, 123);
I have lists where strings correspond with values. For example, in a company list
I have about 50 million lists of strings in Python like this one: [1,
I have list of strings like this FirstName-Lastname (separated by a dash -) I
I have a Powershell script where I would like to create a generic List
Say I have two lists or arrays of strings. For example: list 1: a,
I have a list of lists of three strings in Python, e.g., m =
I have multiple lists of strings, IList<string> , that I want to consolidate in

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.