如何从图像 URL 列表创建图像库?

发布于 2024-12-11 01:43:16 字数 1134 浏览 2 评论 0原文

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

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 类型函数。

在 .aspx 页面中,除了 ItemTemplate 之外,我还需要设置其他内容吗?

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

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();

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.

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2024-12-18 01:43:16

您需要将两个类添加到您的项目的 App_Code 目录中。

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

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 页面上的设计模式下,选择中继器并单击右上角。您单击选择的数据源,添加新的数据源。您选择对象(如果需要,可以重命名),然后单击“确定”。

然后取消选中该复选框以查看可以使用的所有对象,选择您创建的类的名称(此处为“工具”)。单击下一步,然后选择 GetImgUrls 方法并单击终止。

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

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

Eval 函数查找属性,而字符串除了“Length”属性之外没有任何属性。这就是为什么你需要创建一个字符串包装器,以便 Eval 可以调用 Value 属性并获取字符串值。

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

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;
    }
}

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.

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.

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文