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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:03:29+00:00 2026-05-26T05:03:29+00:00

I have the following Helper class to generate a <ASP:Table> control dynamically. using System;

  • 0

I have the following Helper class to generate a <ASP:Table> control dynamically.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{
    public class TableDisplay10X2
    {
        # region public properties

        # region Styles

        public string TableStyle { get; set; }
        public string HeaderStyle { get; set; }
        public string CommonHeaderColumnStyle { get; set; }
        public string CommonRowStyle { get; set; }
        public string CommonColumnStyle { get; set; }
        public string[] HeaderColumnStyles { get; set; }
        public string[] RowStyles { get; set; }
        public string[,] ColumnStyles { get; set; }

        # endregion Styles

        public IList<RowInfo> TableRows { get; set; }

        # endregion

        public TableDisplay10X2()
        {
            HeaderColumnStyles = new string[2];
            RowStyles = new string[10];
            ColumnStyles = new string[10, 2];
            TableRows = new List<RowInfo>();
        }       

        public Table Create(Panel panel)
        {
            var table = new Table();
            panel.Controls.Add(table);
            table.CssClass = TableStyle;

            // Add Header
            var headRow = new TableHeaderRow();
            var leftHeaderColumn = new TableHeaderCell();
            var rightHeaderColumn = new TableHeaderCell();
            headRow.Cells.Add(leftHeaderColumn);
            headRow.Cells.Add(rightHeaderColumn);
            table.Rows.Add(headRow);
            headRow.CssClass = HeaderStyle;            
            leftHeaderColumn.CssClass = (HeaderColumnStyles[0] != null) ? HeaderColumnStyles[0] : CommonHeaderColumnStyle;            
            rightHeaderColumn.CssClass = (HeaderColumnStyles[1] != null) ? HeaderColumnStyles[1] : CommonHeaderColumnStyle;            

            for (int count = 0; count < TableRows.Count; count++)
            {
                if (TableRows[count] != null)
                {
                    TableRow tr = new TableRow();
                    TableCell leftCell = new TableCell();
                    TableCell rightCell = new TableCell();
                    tr.Cells.Add(leftCell);
                    tr.Cells.Add(rightCell);
                    table.Rows.Add(tr);

                    leftCell.Text = TableRows[count].LeftColumn;
                    rightCell.Text = TableRows[count].RightColumn;
                    tr.CssClass = (RowStyles[count] != null) ? RowStyles[count] : CommonRowStyle;
                    leftCell.CssClass = (ColumnStyles[count, 0] != null) ? ColumnStyles[count, 0] : CommonColumnStyle;                                     
                    rightCell.CssClass = (ColumnStyles[count, 1] != null) ? ColumnStyles[count, 1] : CommonColumnStyle;
                }
            }


            return table;
        }
    }

    public class RowInfo
    {
        public string LeftColumn { get; set; }
        public string RightColumn { get; set; }
    }
}

and Creating the table control using the following code

var  presidentTable = new TableDisplay10X2();
            presidentTable.TableStyle = "Width:400px; Border: 1px solid #cccccc; margin:10px font-family:Arial; font-size:24px";
            presidentTable.TableRows.Add(new RowInfo { LeftColumn = "President", RightColumn= "Mr D R" });
            presidentTable.TableRows.Add(new RowInfo { LeftColumn = "Address", RightColumn = "Add 1" });
            presidentTable.TableRows.Add(new RowInfo { RightColumn = "Add 2" });
            presidentTable.TableRows.Add(new RowInfo { RightColumn = "Add 3" });
            presidentTable.TableRows.Add(new RowInfo { RightColumn = "Add 4" });
            presidentTable.Create(panelBoardMembers);

The table is getting created but the style is not getting applied. What is the issue?

  • 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-26T05:03:30+00:00Added an answer on May 26, 2026 at 5:03 am

    Because of you are setting the class attribute for table, by the css-styles! While you should set it by a css-class-name. See:

    table.CssClass = TableStyle;
    

    that will be rendered as:

    <table class="Width:400px; Border: 1px solid #cccccc; margin:10px font-family:Arial; font-size:24px">
    

    Instead, you can use a CssStyleCollection property for helper-class (for example name it CssStyles) or use the following code:

    // table.CssClass = TableStyle; YOU SHOULD REMOVE THIS LINE!!!
    table.Attributes.Add("style", TableStyle);
    

    that will be rendered as:

    <table style="Width:400px; Border: 1px solid #cccccc; margin:10px font-family:Arial; font-size:24px">
    

    This will resolve your problem. Regards.

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

Sidebar

Related Questions

I currently have a class file with the following enumeration: using System; namespace Helper
I have the following code to generate some spans using cakephp's helper <div id=numberRow>
I have the following methods in an enum helper class (I have simplified it
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have the following C# helper class which retrieves a Json String from a
I have following class with one static method: public class Helper { public static
I have the following DB helper class: public int studentExists(String studid) { Cursor dataCount
I have the following helper class (simplified): public static class Cache { private static
I currently have a helper class to perform rudimentary AsyncTasks such as the following.
In a makefile, I have the following line: helper.cpp: dtds.h Which ensures that helper.cpp

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.