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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:24:59+00:00 2026-06-15T19:24:59+00:00

I am writing an ASP.NET page which reads data from a database and needs

  • 0

I am writing an ASP.NET page which reads data from a database and needs to show it in a table. For some reason, I don’t want to use the gridView.

How do I show the data in a table on the HTML page?

This is my C# code:

        SqlConnection thisConnection = new SqlConnection(dbConnection);
        SqlCommand thisCommand = thisConnection.CreateCommand();
        thisCommand.CommandText = "SELECT * from Test";
        thisConnection.Open();
        SqlDataReader reader = thisCommand.ExecuteReader();

        while (reader.Read())
        {
            int id = reader.GetInt32(0);
            string Name = reader.GetString(1);
            string Pass = reader.GetString(2);                   
        }

        thisConnection.Close();

This is my ASPX page:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/test.master" CodeFile="test.aspx.cs" Inherits="test" %>

<asp:Content ID="BodyContent" runat="server"  ContentPlaceHolderID="ContentPlaceHolder">
    <table width="100%" align="center" cellpadding="2" cellspacing="2" border="0" bgcolor="#EAEAEA" >
        <tr align="left" style="background-color:#004080;color:White;" >
            <td> ID </td>                        
            <td> Name </td>            
            <td>Pass</td>                        
        </tr>

        **<%--Need the while output into here--%>**

    </table>
</asp:Content>
  • 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-15T19:25:01+00:00Added an answer on June 15, 2026 at 7:25 pm

    Basically use the classic ASP\PHP\Spaghetti code approach.

    First of all, place your code in one public method that returns a string.
    The method:

    public string getWhileLoopData()
    {
            string htmlStr = "";
            SqlConnection thisConnection = new SqlConnection(dbConnection);
            SqlCommand thisCommand = thisConnection.CreateCommand();
            thisCommand.CommandText = "SELECT * from Test";
            thisConnection.Open();
            SqlDataReader reader = thisCommand.ExecuteReader();
    
            while (reader.Read())
            {
                int id = reader.GetInt32(0);
                string Name = reader.GetString(1);
                string Pass = reader.GetString(2);
                htmlStr +="<tr><td>"+id+"</td><td>"+Name+"</td><td>"+Pass+"</td></tr>"                   
            }
    
            thisConnection.Close();
            return htmlStr;
    }
    

    Then you can use the <%=getWhileLoopData()%> tag in ASP.NET that is equal to <%Response.Write(getWhileData())%>

    It should look something like this:

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/test.master" CodeFile="test.aspx.cs" Inherits="test" %>
    
    <asp:Content ID="BodyContent" runat="server"  ContentPlaceHolderID="ContentPlaceHolder">
        <table width="100%" align="center" cellpadding="2" cellspacing="2" border="0" bgcolor="#EAEAEA" >
            <tr align="left" style="background-color:#004080;color:White;" >
                <td> ID </td>                        
                <td> Name </td>            
                <td>Pass</td>                        
            </tr>
    
            <%=getWhileLoopData()%>
    
        </table>
    </asp:Content>
    

    There is also the option to use an repeater control and bind the data from your DB to an Item Template of your liking.

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

Sidebar

Related Questions

Duplicate Why don’t self-closing script tags work? I'm writing an ASP.net page, which have
I have an asp.net website which contains a Thread that fetches some data from
I'm writing an ASP.NET app in which a table of objects is created by
I am writing an asp.net page, and I'm having some trouble submitting the form.
I'm writing an ASP.Net MVC application using Jquery to post some data to my
I've heard that writing out the entire ASP.NET page in one go helps performance.
I'm writing an application which uses ASP.NET MVC with JSON.NET as the server, sending
I'm writing an small ASP.NET MVC app, which allow read and comment for a
I'm writing an intranet ASP.NET page using VB.NET. I've run into a particularly nasty
I am writing an ASP.NET MVC 2.0 application which requires users to log in

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.