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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:19:41+00:00 2026-05-20T07:19:41+00:00

I’m building a html table dynamically in an ASP.NET code behind file using C#.

  • 0

I’m building a html table dynamically in an ASP.NET code behind file using C#. I basically loop through a set of data which is an unknown number of records and split a string containing all the values to make the required number of tds. I display the html by assigning it to an asp:Literal control. However I can’t get the table to fit the screen – the browser is adding a horizontal scroll bar and the full table is well off the screen. I tried in IE 8 and FF 3.6.13. Most things I’ve read online about it say to set the width to 100%. I’m doing this but it’s having no effect. Does assigning html to a Literal control like this render the same as it would any other way? The aspx page has a master page and the front end code for the aspx page is:

EDIT: I’ve pasted the outputted html code here:
http://www.codepaste.net/nza7r8

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" EnableViewState="False">
    <div><br />
        <asp:Literal ID="Literal1" runat="server"></asp:Literal><br />
    </div>
    <div id="paging">
        <asp:Button ID="btnPrev" runat="server" Text="Prev" CssClass="niceInput" onclick="btnPrev_Click" Enabled="False" />
        <asp:Button ID="btnNext" runat="server" Text="Next" CssClass="niceInput" onclick="btnNext_Click" Enabled="False" />
        <asp:Label class="Grid" ID="lblPageNumber" runat="server"/>&nbsp;&nbsp;&nbsp;
        <asp:Label class="Grid" ID="lblTotalRecords" runat="server"/>
    </div><br />    
</asp:Content>

Here’s the code behind:

StringBuilder stringBuilder = new StringBuilder();
List<string> errorColumnsList;

stringBuilder.Append("<table align='center' width='100%' style='border-style:inset'>");

//1st element is header so do this separately
stringBuilder.Append("<tr style='font-size:smaller; font-weight:bold'>");
stringBuilder.Append("<td>ID</td><td>Error type</td>");
errorColumnsList = new List<string>(items[0].HoldingsError.Split("||".ToCharArray()));

foreach (string str in errorColumnsList)
{
    stringBuilder.Append("<td>" + str.Trim() + "</td>");
}

stringBuilder.Append("</tr>");

//Continue on with the rest of the data - remove header first
items.Remove(items[0]);

foreach (HoldingsErrorItem item in items)
{
    stringBuilder.Append("<tr style='font-size:smaller'>");
    stringBuilder.Append("<td>" + item.HoldingsErrorID + "</td><td>" + item.ErrorType + "</td>");
    errorColumnsList = new List<string>(item.HoldingsError.Split("||".ToCharArray()));

    foreach (string str in errorColumnsList)
    {
        stringBuilder.Append("<td>" + str.Trim() + "</td>");
    }

    stringBuilder.Append("</tr>");
}

stringBuilder.Append("</table>");

Literal1.Text = stringBuilder.ToString();
  • 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-20T07:19:41+00:00Added an answer on May 20, 2026 at 7:19 am

    Setting the .Text property of an asp:Literal to be a string of HTML will indeed end up treating the HTML for the table no differently to if it was explicitly in the page.

    How many columns are there in the resulting table? Usually, if the table would be wider than the window, each table cell in HTML will wrap its content on space characters to reduce the table width to fit, until it’s down to single words. Once it hits that point, it cannot wrap any further and it’s irrelevant what width you set – it will be forced to be as wide as the total widths of the longest words in each column.

    Edit: The demonstration page shows what I expected: a large number of columns and, although each is “shrink wrapped” to the minimum width possible (by wrapping content on whitespace), the total width is still large.

    I’m afraid this is just how HTML tables work. I tried adding style="max-width:3%;overflow:hidden;" to each td, but even that doesn’t stop the cells stretching to fit their longest unwrappable piece of content.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.