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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:58:50+00:00 2026-06-02T12:58:50+00:00

I’m trying to manually add three headers to a table. The table fills out

  • 0

I’m trying to manually add three headers to a table. The table fills out fine with data from the SqlDataReader, but I’m having trouble getting the first row to stick.

        TableRow iRow = new TableRow();
        TableCell iCell = new TableCell();
        iCell.Text = "SUBMITTED BY";
        iRow.Cells.Add(iCell);
        iCell.Text = "ON";
        iRow.Cells.Add(iCell);
        iCell.Text = "ISSUE DESCRIPTION";
        iRow.Cells.Add(iCell);
        table.Rows.Add(iRow);

causes only the last entry, in this case, ISSUE DESCRIPTION, to show up on the table. I’ve found a workaround in

        TableRow iRow = new TableRow();
        TableCell iCell = new TableCell();
        TableCell iCell2 = new TableCell();
        TableCell iCell3 = new TableCell();
        iCell.Text = "SUBMITTED BY";
        iRow.Cells.Add(iCell);
        iCell2.Text = "ON";
        iRow.Cells.Add(iCell2);
        iCell3.Text = "ISSUE DESCRIPTION";
        iRow.Cells.Add(iCell3);
        table.Rows.Add(iRow);

but it’s bothering me how much messier that is. Is something wrong with my logic, or is there something I’m missing in C#? I’ve got a pretty good handle on C, but just started C# a couple weeks ago.

Thanks!

  • 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-02T12:58:51+00:00Added an answer on June 2, 2026 at 12:58 pm

    is there something I’m missing in C#

    Sounds like it, yes.

    This:

    TableCell iCell = new TableCell();
    

    creates a TableCell object, and assigns a reference to it to the iCell variable. The value of iCell is just a reference to the object. It’s not the object itself. This:

    iRow.Cells.Add(iCell);
    

    passes that reference to the Add method. It doesn’t pass an object to Add – you can never do that in C#. So your row ends up with lots of references to the same cell, and all the changes you’ve made in lines like this:

    iCell.Text = "ON";
    

    just overwrite each other, as they’re making changes to the same object.

    You may find these articles useful:

    • References and values
    • Parameter passing in C#

    Personally I would change your code to use collection initializers and object initializers:

    TableRow row = new TableRow {
        Cells = {
            new TableCell { Text = "SUBMITTED BY" },
            new TableCell { Text = "ON" },
            new TableCell { Text = "ISSUE DESCRIPTION" },
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.