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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:17:45+00:00 2026-06-18T18:17:45+00:00

I have the following in code behind: [WebMethod] public static string GenerateHtml(string id) {

  • 0

I have the following in code behind:

[WebMethod]
public static string GenerateHtml(string id)
{
    //return id;
    DataView vwMain2;
    try
    {
        DbProviderFactory dbf = DbProviderFactories.GetFactory();
        using (IDbConnection con = dbf.CreateConnection())
        {
            string sSQL;
            sSQL = "select top 20                " + ControlChars.CrLf
                 + " ASSISTING_FILE_ID, DATE_ENTERED, CLIENT_CLAIM_NUM, PRIMARY_INSURED, PRIMARY_CLAIMANT, LOB_ID, FILE_STATUS, BRANCH_NAME," + ControlChars.CrLf
                 + " OWNERS_FIRST_NAME, OWNERS_LAST_NAME, OWNERS_NAME, OWNERS_EMAIL, OWNERS_OFFICE_PHONE, OWNERS_FAX_PHONE, OWNERS_CELL_PHONE" + ControlChars.CrLf
                 + "  from vwFILES_DetailViewWithOwners" + ControlChars.CrLf
                 + " where 1 = 1                    " + ControlChars.CrLf;
            //+ " where 1 = 1 and WEB_USER_ID = '" + Security.USER_ID.ToString() + "'" + ControlChars.CrLf;
            using (IDbCommand cmd = con.CreateCommand())
            {
                cmd.CommandText = sSQL;

                using (DbDataAdapter da = dbf.CreateDataAdapter())
                {
                    ((IDbDataAdapter)da).SelectCommand = cmd;
                    using (DataTable dt = new DataTable())
                    {
                        da.Fill(dt);
                        vwMain2 = dt.DefaultView;
                        GridView2.DataSource = vwMain2;

                            GridView2.DataBind();

                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
        //lblError.Text = ex.Message;
    }

}

I want to loop through that and create an HTML table in the following format:

<table>
    <tbody>
        <tr>
            <th>Column Header</th>
        </tr>
        <tr>
            <td>Column Data</td>
        </tr>
    </tbody>
</table>

What is the best way to do this? I want to return the HTML once it is generated.

Thank you.

  • 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-18T18:17:46+00:00Added an answer on June 18, 2026 at 6:17 pm

    I’d just use a stringBuilder and piece together the HTML by hand in some loops.

    StringBuilder sb = new StringBuilder();
    
    sb.append('<table><tbody>');
    
    foreach(DataRow r in dt.Rows)
    {
         sb.append('<tr><th>' + r["ColumnHeader"] + '</th></tr>');
         sb.append('<tr><th>' + r["ColumnData"] + '</th></tr>');
    }
    
     sb.append('</tbody></table>');
    
    
      return sb.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code behind: [WebMethod] public static string GenerateHtml(string id) { //return
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have the following code behind: public partial class _Default : System.Web.UI.Page { List<GlassesCollection>
I have the following code behind: protected string VcdControlPanelLink { get; set; } protected
I have the following code behind a button in Visual Studio 2010 private void
I have the following code that I want to return to a variable t
In my code behind in C# I have the following code. How do I
I have following code, <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml>
I have the following code behind that was, until recently, working fine and dandy!
I have the following code in a User Control: public partial class MyControl :

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.