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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:36:58+00:00 2026-05-13T20:36:58+00:00

I am trying to create a table dynamically in my code behind. My problem

  • 0

I am trying to create a table dynamically in my code behind. My problem is I have a count of how many controls I want added to each TableRow after which I want to add that TableRow to the table and then start a new row. Here is the code I have no far but it just adds one row and does not move any of the controls to a seperate new row.

public void FillTable(string DB, int? appID, string function, int? rID, string UserId, int ControlsperRow)
{
    OneEvaDataContext datacontext = new OneEvaDataContext();

    var results = datacontext.sp_Build_Menu_Field_Names(DB, appID, function, rID);
    int controlCount = 0;

    TableRow tr = new TableRow();
    foreach (sp_Build_Menu_Field_NamesResult result in results)
    {

            TableCell tcLabel = new TableCell();
            TableCell TcControl = new TableCell();
            Control control = new Control();

            control = DynamicControlReturn.ReturnControl(result.Param_Name, result.Build_Options_Type_NAME, UserId);
            control.ID = "control" + controlCount.ToString();

            _controlClientIDList.Add(control.ClientID);

            tcLabel.Text = result.Param_Label;
            TcControl.Controls.Add(control);
            tr.Cells.Add(tcLabel);
            tr.Cells.Add(TcControl);

            controlCount = controlCount + Convert.ToInt32(result.TD_Len);

            if (controlCount == ControlsperRow)
            {
                base.Controls.Add(tr);
                controlCount = 0;
            }
    }
} 

I would have thought that doing the .Add only when I am finished building that row would work but I guess since I’m using the same TableRow “tr” It is only putting in just one row.

EDIT: in the is context base is my class which looks like this:

  public class Dynamic_Search_Table : System.Web.UI.WebControls.Table
    {
  • 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-13T20:36:59+00:00Added an answer on May 13, 2026 at 8:36 pm

    Move

    TableRow tr = new TableRow();
    

    into the foreach, and add

    this.Add(tr);
    

    at the end of the foreach.


    Edit: Change

    if (controlCount == ControlsperRow)
    {
        base.Controls.Add(tr);
        controlCount = 0;
    }
    

    To

    if (controlCount == ControlsperRow)
    {
        base.Controls.Add(tr);
        controlCount = 0;
        tr = new TableRow();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 317k
  • Answers 317k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Select the block in visual mode, and then use :s/^/"/.… May 13, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer If you mean unmanaged objects then yes, you should be… May 13, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer The answer below uses git log: I mentioned a similar… May 13, 2026 at 11:44 pm

Related Questions

UPDATE: I found a solution. See my Answer below. My Question How can I
i am simple cart page where it displays the content in table form and
I have two different tables from which I need to pull data blogs which
I have some predicates being dynamically built that have the following signature passes through
I've been trying a lot of different things that I would think would work

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.