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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:08:20+00:00 2026-05-26T15:08:20+00:00

If I want to combine asp.net code with html (mark up) file, I need

  • 0

If I want to combine asp.net code with html (mark up) file, I need to open <% %> and execute teh code.

What If I want to iterate over a database with select query while feeding information and creating rows. For example:

<table>

<%
   foreach(DataRow dr in dataset.Tables["empoloyees"].Rows)
   {
%>
<tr>
<td>
      <asp:Label runat="Server" Text="<% dr[FirstName].toString(); %>"/>
</td>
<td>
      <asp:Label runat="Server" Text="<%dr[LastName].toString();%>"/>
</td>
</tr>
<%
   }
%>
</table>

Is the syntax correct..and is that practice good (it is always used in php) ? or should I bind the data to the label somehow?(no idea how. but somehow)?

  • 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-26T15:08:21+00:00Added an answer on May 26, 2026 at 3:08 pm

    First and most important thing – do not mix business logic and data access functionality with the data representation markup!

    Supposing you are using WebForms, you can use Repeater control which is bound in the code behind of a page/control (aspx.cs/ascx.cs) so View stay decoupled and just bound to specific properties of data source:

    ASPX:

    <asp:Repeater ID="employees" runat="server">   
    <HeaderTemplate>   
    <table> 
    </HeaderTemplate>   
    <ItemTemplate>   
    <tr>   
    <td>   
       <asp:Label runat="Server" 
                  Text="<%# DataBinder.Eval(Container.DataItem, "FirstName") %>"/> 
    </td> 
    <td>        
    
       <asp:Label runat="Server" 
                  Text="<%# DataBinder.Eval(Container.DataItem, "LastName") %>"/> 
    </td>   
    </tr>   
    </ItemTemplate>   
    <FooterTemplate>   
    </table>
    </FooterTemplate>   
    </asp:Repeater>   
    

    Code Behind: (Page_Load() for instance)

    employees.DataSource = dataset.Tables["empoloyees"].Rows;
    employees.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we combine Silver-light with Asp.net to implement SEO? I mean i want to
I want to use Ninject in a project which combines ASP.Net webforms and ASP.Net
I am writing an asp.net MVC app that drives an IPhone application. I want
I'm using ASP.NET MVC 3 Framework and I want to use Google Maps (v3)
My ASP.NET web app runs fine under IIS 7.5. But I want to make
I need to build a list of all roles on an ASP.NET web site,
Is there some way to intercept the HTML output stream in asp.net and make
I am using ASP.NET MVC 3 with Entity Framework 4 using POCOs and want
I'm using an UpdatePanel in ASP.NEt WebForms to upload a image. I want to
I'm working on a few ASP.NET MVC projects which all require database functionality. Unfortunately,

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.