如何从图像 URL 列表创建图像库? [英] how can I create an image gallery from a list of image URLs?

查看:52
本文介绍了如何从图像 URL 列表创建图像库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用 Amazon SimpleDB 获取大量图像 URL.我试图了解将 URL 绑定到中继器并创建照片库的最佳方法.中继器可能不是最好的数据控件,所以如果你能想到更好的方法,我愿意接受建议.

I'm able to get a bunch of image URLs using Amazon SimpleDB. I'm trying to understand the best way to bind the URL's to a Repeater and create a photo gallery. Repeater may not be the best Data control, so I'm open to suggestions if you can think of a better way.

List<string> imgURLS = new List<string>();    

String selectExpression = "Select * From Gallery Where Category = 'imgurls'";
SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
SelectResponse selectResponse = sdb.Select(selectRequestAction);

if (selectResponse.IsSetSelectResult())
{
    SelectResult selectResult = selectResponse.SelectResult;
    foreach (Item item in selectResult.Item)
    {
        Console.WriteLine("  Item");
        if (item.IsSetName())
        {
           imgURLS.Add(item.Value)  //the URL of the image
        }
    }
}

 Repeater1.DataSource = imgURLS;
 Repeaster1.DataBind();

在这个例子中,我只是构建了一个 URL 的 List[string],但是我在网上看到的所有例子都使用了一个带有 Eval 类型语句的内联 DataBinding SQL 类型函数.

In this example, I just building a List[string] of the URLs, but all the examples I see online use an inline DataBinding SQL type function with an Eval type statement.

在 .aspx 页面中,除了 ItemTemplate 之外,我是否必须设置任何其他内容?

In the .aspx page, do I have to set any thing other than the ItemTemplate?

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
   //How do I direct my DataSource here?
    </ItemTemplate>
</asp:Repeater>

推荐答案

您需要在 App_Code 目录中为您的项目添加两个类.

You need to add two classes to your project in the App_Code directory.

一个将包含字符串类的包装器(我称之为 StringWrapper),另一个将包含一个 List 类型的方法.最后一个方法将返回您的 imgURLS 列表.

One will contain a wrapper for the string class (I called it StringWrapper), and the other will contain a method of type List. This last method will return your imgURLS list.

public class StringWrapper
{
    public string Value
    { get; set; }
    public StringWrapper(string s)
    {
        this.Value = s;
    }

    public static implicit operator StringWrapper(string s)
    {
        return new StringWrapper(s);
    }
}

<小时>

public static class Tools
{
    public static List<StringWrapper> GetImgUrls()
    {
        List<StringWrapper> imgURLS = new List<StringWrapper>();    

        String selectExpression = "Select * From Gallery Where Category = 'imgurls'";
        SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
        SelectResponse selectResponse = sdb.Select(selectRequestAction);

        if (selectResponse.IsSetSelectResult())
        {
            SelectResult selectResult = selectResponse.SelectResult;
            foreach (Item item in selectResult.Item)
            {
                Console.WriteLine("  Item");
                if (item.IsSetName())
                {
                   imgURLS.Add(item.Value)  //the URL of the image
                }
            }
        }
        return imgURLS;
    }
}

<小时>

然后在 aspx 页面上的设计模式中,选择转发器并单击右上角.您单击选择的数据源,添加新的数据源.您选择对象(如果需要,可以重命名)并单击确定.


Then in design mode on your aspx page, you select the repeater and click the top right corner. You click chose datasource, add new datasource. You select object, (rename it if you want) and click ok.

然后取消选中复选框以查看可以使用的所有对象,您选择了您创建的类的名称(这里是工具).单击下一步,然后选择 GetImgUrls 方法并单击终止.

Then you uncheck the checkbox to see all objects that can be used, you chose the name of the class you created (here, Tools). You click next, then you select the GetImgUrls Method and click terminate.

然后要使用它,只需在您的 ItemTemplate 中调用 <%# Eval("Value") %>,例如:

Then to use it, just call <%# Eval("Value") %> in your ItemTemplate, for example:

    <ItemTemplate>
        <img src='<%# Eval("Value") %>' />
    </ItemTemplate>

Eval 函数查找属性,字符串除了长度"属性外没有任何属性.这就是为什么你需要做一个stringwrapper,以便Eval可以调用Value属性并获取字符串值.

The Eval function looks for properties, and a string has no property except the "Length" property. That is why you need to make a stringwrapper, so that Eval can call the Value property and obtain the string value.

这篇关于如何从图像 URL 列表创建图像库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆