2

I am trying to print out the elements from an arraylist in a table. But they don't show up in tags. But they appear right up on the webpart title with a single line text.

<table class="table table-hover">
    <thead>
        <tr>
            <th>First Column</th>
            <th>Second Column</th>
        </tr>
    </thead>
    <tbody>
        <%

            lstTable = Data.DTable.Tablo();
            foreach (ETable temp in lstTable)
            {
        %>
        <tr>
            <td><%HttpContext.Current.Response.Write(temp.contact);%></td>
            <td><% HttpContext.Current.Response.Write(temp.companyName);%></td>
        </tr>
        <%}%>
    </tbody>
</table>
1

Try

<table class="table table-hover">
    <thead>
        <tr>
            <th>First Column</th>
            <th>Second Column</th>
        </tr>
    </thead>
    <tbody>
        <%
            lstTable = Data.DTable.Tablo();
            foreach (ETable temp in lstTable)
            {
        %>
        <tr>
            <td><%= temp.contact %></td>
            <td><%= temp.companyName %></td>
        </tr>
        <%}%>
    </tbody>
</table>
  • Thanks but now I am getting some errors from the ascx.g.cs file such as " Invalid expression term ')' ". I tried to clean the project but didn't work. – teteckr May 11 '15 at 14:30
  • don't you have a separate acsx.cs file? the code file for the control? – Arsalan Adam Khatri May 11 '15 at 14:57
  • Watch out for HTML and JS injection!! Use <%: ... %> instead of <%= ... %> in order to HTML-escape content. – Max Heiber Dec 14 '15 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.