3

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 Answer 1

2

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>
3
  • 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
    Commented May 11, 2015 at 14:30
  • don't you have a separate acsx.cs file? the code file for the control? Commented May 11, 2015 at 14:57
  • Watch out for HTML and JS injection!! Use <%: ... %> instead of <%= ... %> in order to HTML-escape content.
    – Max Heiber
    Commented Dec 14, 2015 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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