简体   繁体   English

使用带有 asp.net ListView 的 Galleria jQuery 插件

[英]Using Galleria jQuery plugin with an asp.net ListView

I am trying to use Galleria with an asp.net ListView that gets the image sources from the database after those images are uploaded.我正在尝试将Galleria与 asp.net ListView 一起使用,该列表视图在上传这些图像后从数据库中获取图像源。 The following is my Listview:以下是我的列表视图:

        <div id="photoAlbumDiv" class="photoAlbumDiv">


        <asp:ListView ID="ListView1" runat="server" DataKeyNames="id" >
            <AlternatingItemTemplate>
                <td runat="server" style="">
                </td>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <td runat="server" style="">
                </td>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <td runat="server" style="">

                </td>
            </InsertItemTemplate>
            <ItemTemplate>
                <td runat="server" style="">
                    <img id="photoAlbumPhotos" src='<%# Eval("img") %>' alt="Image Not Found" class="photoAlbumPhotos" />
                </td>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server" border="0" style="">
                    <tr ID="itemPlaceholderContainer" runat="server">
                        <td ID="itemPlaceholder" runat="server">
                        </td>
                    </tr>
                </table>
                <div style="">
                </div>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <td runat="server" style="">
                    id:
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    img:
                    <asp:Label ID="imgLabel" runat="server" Text='<%# Eval("img") %>' />
                    <br />
                </td>
            </SelectedItemTemplate>
        </asp:ListView>

    </div>

and here is my jquery:这是我的 jquery:

                        <script type="text/javascript">
                        Galleria.loadTheme('Scripts/themes/classic/galleria.classic.min.js');
                        $("#photoAlbumDiv").galleria({
                            height: 1000,
                            width: 1000
                        });
                         </script>

Can it be done, thanks可以做吗,谢谢

You're going about things the wrong way and making it more difficult than it needs to be.您以错误的方式处理事情,并使其变得比需要的更困难。 The Galleria plugin expect HTML to be organized as follows: Galleria 插件期望 HTML 组织如下:

<div>
    <img />
    <img />
    <img />
    ...
    <img />
</div>

As you can see, there is nothing but images inside of a div.如您所见,div 内只有图像。 You have a table structure which will not work.您有一个不起作用的表结构。 Use the following code to run a quick sample and you'll see how easy it is.使用以下代码运行一个快速示例,您将看到它是多么容易。

Javascript Javascript

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="galleria/galleria-1.2.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
        $("#gallery").galleria({
            width: 200,
            height: 300
        });
    });        
</script>

ASPX ASPX

<asp:ListView runat="server" ID="lvw">
    <LayoutTemplate>
        <div id="gallery">
            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
        </div>
    </LayoutTemplate>
    <ItemTemplate>
        <img id="photoAlbumPhotos" src='<%# Eval("img") %>' alt="Image Not Found" class="photoAlbumPhotos" />
    </ItemTemplate>
</asp:ListView>

C# C#

protected void Page_Load(object sender, EventArgs e)
{
    lvw.DataSource = //Build datasource from database;
    lvw.DataBind();
}

And that's it.就是这样。 You should have a simple Galleria gallery running in the browser.您应该在浏览器中运行一个简单的 Galleria 画廊。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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