2016-07-19 111 views
0

我有一个公共类和一个公共列表。如何访问代码后面的列表变量aspx页面

public List<yahoo> yahooRec = new List<yahoo>(); 

public class yahoo 
{ 

    public string url { get; set; } 
    public string title { get; set; } 
    public string descripton { get; set; } 
} 

我的清单得到它的值在foreach循环中。我只是想用我的名单在一个中继器

<asp:Repeater id="Rep" runat="server"> 
<ItemTemplate> 
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%= yahoorec.url %>' Text='<%= yahoorec.title %>' /> 
<p> <%= yahoorec.description %> </p> 
</ItemTemplate> 
</asp:Repeater> 

但它不工作。任何人都可以帮助我吗?

回答

1

方法可以使用:

<asp:Repeater ID="Rep" runat="server"> 
    <ItemTemplate> 
     <a href="<%# Eval("url") %>"><%# Eval("title") %></a> 
     <p><%# Eval("Url")%> </p> 
    </ItemTemplate> 
</asp:Repeater> 

或者,你可以钩入Rep.I temDataBound事件,找到您的控件,并将其填充到代码隐藏中。

1

使用按照您的aspx.cs页面

Rep.DataSource = yahooRec; 

,并在你的aspx页面

<asp:Repeater ID="Rep" runat="server"> 
<ItemTemplate> 
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("url") %>'></asp:Label> 
    <br /> 
    <asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'></asp:Label> 
    <br /> 
    <asp:Label ID="Label3" runat="server" Text='<%# Eval("descripton") %>'></asp:Label> 
</ItemTemplate> 

相关问题