473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fixed column width for table created from database

hi there, i've recently started a student placement as a web developer and wondered if anyone could help me with the following problem:

I'm using an ashx file to access messages that are stored in a database and outputting the results into a string builder. The problem I'm having with this method is that depending on the varying length of user names, messages etc. That the end result can appear messy when output onto the web browser. I will submit the code for the ashx file that I am using:

Expand|Select|Wrap|Line Numbers
  1. <%@ WebHandler Language="C#" Class="AjaxHandler" %>
  2.  
  3. using System;
  4. using System.Data;
  5. using System.Text;
  6. using System.Web;
  7. using ChatClassLibrary.DataAccess;
  8.  
  9. public class AjaxHandler : IHttpHandler {
  10.  
  11.     public void ProcessRequest (HttpContext context) {
  12.         context.Response.ContentType = "text/plain";
  13.         context.Response.Expires = 0;
  14.         context.Response.Clear();
  15.  
  16.         int userID = Convert.ToInt32(context.Request.Params["uid"]);
  17.         int lastRead = Messages.GetLastReceived(userID);
  18.  
  19.         DataTable results = Messages.GetLatestMessages(userID, lastRead);
  20.  
  21.         if (results.Rows.Count > 0)
  22.         {
  23.             StringBuilder sb = new StringBuilder();
  24.             sb.Append("<table border='0' width= '750px' id='chatTable'  class='overflow' >");
  25.            ;
  26.  
  27.             sb.Append("<tbody>");
  28.             foreach (DataRow row in results.Rows)
  29.             {
  30.                 sb.Append("<tr width='200px'>");
  31.  
  32.                 sb.Append("<td style='width:50px' >");
  33.                 string userName = row["UserName"].ToString();
  34.                 sb.Append(userName);
  35.                 sb.Append("</td>");
  36.  
  37.                 sb.Append("<td style='width:50px'>");
  38.                 string message = row["MsgContent"].ToString();
  39.                 sb.Append(message);
  40.                 sb.Append("</td>");
  41.  
  42.                 sb.Append("<td style='width:50px'>");
  43.                 string time = row["TimeSent"].ToString();
  44.                 sb.Append(time);
  45.                 sb.Append("</td>");
  46.  
  47.                 sb.Append("<td style='width:50px'>");
  48.                 string delete = "Del";
  49.                 sb.Append(delete);
  50.                 sb.Append("</td>");
  51.  
  52.                 sb.Append("</tr>");
  53.  
  54.  
  55.             }
  56.             sb.Append("</tbody>");
  57.             sb.Append("</table>");
  58.             context.Response.Write(sb.ToString());
  59.         }
  60.         else
  61.         {
  62.             context.Response.Write("");
  63.         }
  64.     }
  65.  
  66.     public bool IsReusable {
  67.         get {
  68.             return false;
  69.         }
  70.     }
  71.  
  72. }
  73.  
Can anyone offer me some advice on the best way to approach this problem? I've only just started the placement and am working with ASP.NET, C#, Javascript, Ajax, DotNetNuke, which are all new to me. I hope I've been reasonlably clear with my question, any replies appreciated.

Thanks,

Davo
Sep 4 '07 #1
1 1351
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

I am moving this to the .NET forum where you'll probably more likely to find someone who can help you solve your problem.

Please use CODE tags when posting code. Thanks!

Normally, you can specify a language too, but there doesn't seem to be one for C# at the moment.
Sep 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bart Heinsius | last post by:
Hi, I can't get my cell widths fixed in a table in IE6. In Mozilla it works, see http://www.xs4all.nl/~margreeh/aa.html . It's the blue cells that remain fixed at 20pt widths in Mozilla but not...
179
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
0
by: TJ Talluto | last post by:
<facts> I have a "month calendar" that always displays exactly 42 days... and alongside is a vertical box that displays the detail (form fields) of any particular select event that appears on the...
1
by: Lalit Bhatia | last post by:
how can we fix first column in DataGrid? Regards, Lalit Bhatia
0
by: Lalit Bhatia | last post by:
thanks for the answer but I need it for windows forms. I have a desktop application where I need to implement this. -- Regards, Lalit Bhatia "Mona" <mona@discussions.microsoft.com> wrote in...
25
by: Michael Schuerig | last post by:
I'm trying to do something seemingly very simple, but it's brought me close to crushing my head on the keyboard. All I want is a table where the head row is fixed and the body columns below are...
0
by: Jay Levitt | last post by:
I'm putting together a small brochureware site to sell my house (http://www.wellesleycarriagehouse.com). The designer used tables initially, but I'm trying to get it as semantic and CSS-ish as...
2
by: dfdavis.mtu | last post by:
I have a table that I dynamically fill with data from a database for medical companies to be able to determine if their patients meet certain criteria. However they want a fixed header for it so...
4
by: Jeff | last post by:
Hey I'm wondering how the Fixed-Width Text Format is What I know is that the top line in this text format will contain column names. and each row beneath the top line represent for example a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.