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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:47:25+00:00 2026-05-20T12:47:25+00:00

I have an application to generate dynamic reports using dynamic SQLs. The results of

  • 0

I have an application to generate dynamic reports using dynamic SQLs. The results of the query will be stored in datatables. I need a function to take the datatable and column width as input and print report in HTML/Text format. The function should identify correct data type of datacolumn and format it as per the data type.

I’ll write a query like this and fetch the values into data table:
SELECT [ID]
,[AccountName] AS [Account Name]
,[TransDate] AS [Trans Date]
,[Amount]
FROM [AccountsTable]

The following is the result set in datatable:
ID [Account Name] [Trans Date] [Amount]
656 Sales Account 14-Apr-2003 13500.00
657 Purchase Account 15-Apr-2003 2000.00
658 Cheque Account 15-Apr-2003 5250.00
659 Sales Account 16-Apr-2003 8000.00
660 Cheque Account 17-Apr-2003 6500.00
661 Purchase Account 18-Apr-2003 1000.00
662 Trade Account 18-Apr-2003 10250.00
663 Discount Account 19-Apr-2003 500.00
Totals: 47000.00

I would like to print these values into HTML File as shown above. Please help me.

  • 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-20T12:47:26+00:00Added an answer on May 20, 2026 at 12:47 pm
    protected void Page_Load(object sender, EventArgs e)
        {
    
            //make your own table here, whathever way you like ie get it from database
            DataTable dt = new DataTable();
            dt.Columns.Add("col1");
            dt.Columns.Add("col2");
            dt.Rows.Add(new object[] { "1", "2" });
            dt.Rows.Add(new object[] { "5", "6" });
    
            RenderTable(dt, 100);
        }
    
        private void RenderTable(DataTable datatable, int column_width)
        {
            Table table = new Table();
    
            //add header to your table 
            TableHeaderRow header = new TableHeaderRow();
    
            foreach (DataColumn dcol in datatable.Columns)
            {
                TableHeaderCell cell = new TableHeaderCell();
                cell.Width = column_width;
    
                Label headlbl = new Label();
                headlbl.Text = dcol.ColumnName;
    
                cell.Controls.Add(headlbl);
                header.Controls.Add(cell);
            }
    
            table.Controls.Add(header);
    
            //fill with data
            foreach (DataRow row in datatable.Rows)
            {
                TableRow tr = new TableRow();
                for (int i = 0; i < datatable.Columns.Count; i++)
                {
                    TableCell td = new TableCell();
                    td.Width = column_width;
    
                    Label label = new Label();
                    label.Text = Convert(row[i], datatable.Columns[i].DataType);
    
                    td.Controls.Add(label);
                    tr.Controls.Add(td);
                }
    
                table.Controls.Add(tr);
            }
    
            //add other rows here ie totals
    
            Page.Controls.Add(table);
    
        }
    
        private string Convert(object val, Type type)
        {
            //do whatever you want with format of your cells
            return val.ToString();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses window.open() to generate dynamic popups. Unfortunately, I've had
I have a PHP application and a need to generate a PDF with the
I have a flex application that needs the ability to generate and execute JavaScript.
Background: we have an application that generates reports from HTML (that may or may
I'm using C# and i have written a locally installed application that dynamically generates
I am using Jquery dynamic form plugin to generate dynamic fields in one of
I have an application that uses a DLL to generate fastReports files. When I
We have an application that generates simulated data for one of our services for
I have exported a COM+ application proxy, which generates MSI and CAB files, and
I have an application that sends messages to an external web service. I build

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.