简体   繁体   中英

ASP.NET display data from a list

I'm trying to display items from a list on my webpage, and I'm getting some errors. Here's my code for the display:

<asp:Repeater id="repZips" runat="server">  
    <HeaderTemplate>
            <table>
                <tr>
    </HeaderTemplate>
        <ItemTemplate>
            <td>
                <%# Container.ItemIndex + 1 %>- <%# Container.DataItem  %>
            </td>
        </ItemTemplate>
        <FooterTemplate>
            </tr></table>
        </FooterTemplate>
</asp:Repeater> 

CodeBehind:

    List<int> zips = (List<int>)ListZips.getZips();
    repZips.DataSource = zips;
    repZips.DataBind();

There are several errors in this codebehind:

-the name repZips.DataSource does not exist in the current context

-the name DataSource does not exist in the current context

-the name zips does not exist in the current context

-the name repZips.DataBind does not exist in the current context
-the name DataBind does not exist in the current context

Do I need to import something or define things differently so that I can use this sort of format? I'm just trying to display everything in the list "zips" on my page.

I figured it out, sorry to bother everyone--thanks for the comments.

If anyone else is having a problem like this, make sure that the stuff I have listed in the code behind is inside the method Page_Load. Worked fine then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM