使用数据库中的数据填充元素

时间:2014-06-14 12:43:09

标签: c# asp.net repeater

我想制作一些用户可以点击它的图片,然后转到带有该相册图片的图片库。 每个algum都有缩略图,标题和图片链接。 在我的代码中,我可以从数据库中获取所有数据。但它并没有出现在网站上。 我知道我做错了什么。但不知道是什么...... 所以,这是我的代码:

在我的模型中,我有这段代码:

public List<Entities.Portfolio> GetAlbuns()
    {
        List<Entities.Portfolio> port = new List<Entities.Portfolio>();
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand("usp_get_all_albuns", connection);
            command.CommandType = CommandType.StoredProcedure;

            SqlDataReader reader = null;
            connection.Open();
            reader = command.ExecuteReader();

            while (reader.Read())
            {
                port.Add(new Entities.Portfolio()
                {
                    Imagem = (byte[])reader.GetValue(0),
                    Link = reader.GetString(1),
                    Title = reader.GetString(2)
                });
            }

        }
        return port;
    }

在我的控制器中,我将调用该方法:

PortfolioController pcontroller = new PortfolioController();
protected List<Entities.Portfolio> GetAlbuns()
    {
        return pcontroller.GetAlbuns();
    }

在我的ASP.NET页面中,我有这个:

 <div class="freshdesignweb" id="Albuns" runat="server">
    <% foreach(var items in GetAlbuns())
       { %>
           <!-- start article 1 -->
                <article class="border c-two" style="background-image:url('<% items.Imagem.ToArray(); %>"')">
                    <div style="opacity: 0;" class="fdw-background">
                        <h4><a href="<% Eval(items.Link.ToString()); %>" style="color:#fff;"><% Eval(items.Title.ToString()); %></a></h4>

                        <p class="fdw-port">
                            <a href="<% Eval(items.Link.ToString()); %>">Abrir Álbum <span class="vg-icon">→</span></a>
                        </p>
                    </div>
                </article>
                <!-- end article 1 -->
    <%} %>

我可以很好地获得所有数据,我在调试模式下测试过。但它并没有出现在页面中。 我知道我做错了什么,你能帮我理解如何解决这个问题吗?

在我的调查中,我读到了

谢谢。

1 个答案:

答案 0 :(得分:0)

你错过了Eval前面的#符号:

"<%# Eval(items.Link.ToString()) %>"