从数据库查看GridView中的图像

本文关键字:图像 GridView 数据库 | 更新日期: 2023-09-27 18:19:53

我有一个三列的网格视图,在上面我只需要制作照片库,我从数据库中获取图像

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    <Columns>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" Width="200px" Height="200px" runat="server" Text='<%#Eval("imageUrl")%>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Image ID="Image1" Width="200px" Height="200px" runat="server" ImageUrl='<%#Eval("imageUrl")%>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" Width="200px" Height="200px" runat="server" Text='<%#Eval("imageUrl")%>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Image ID="Image1" Width="200px" Height="200px" runat="server" ImageUrl='<%#Eval("imageUrl")%>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" Width="200px" Height="200px" runat="server" Text='<%#Eval("imageUrl")%>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Image ID="Image1" Width="200px" Height="200px" runat="server" ImageUrl='<%#Eval("imageUrl")%>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=BASSAM-PC'SQLEXPRESS;Initial Catalog=fame;Persist Security Info=True;User ID=sa;Password=root" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [imageURL] FROM [studentNew] WHERE ([type] = @type)">
     <SelectParameters>
         <asp:Parameter DefaultValue="gallary" Name="type" Type="String" />
     </SelectParameters>
</asp:SqlDataSource>

问题是同一张照片在列中出现三次,我希望它在每列中逐一更改我怎么能做到??

从数据库查看GridView中的图像

我找到了解决方案,改为使用列表项而不是网格视图

<asp:ListView ID="ImageListView" runat="server" ItemPlaceholderID="itemPlaceHolder" GroupPlaceholderID="groupPlaceHolder" OnItemCommand="ImageListView_ItemCommand">
    <LayoutTemplate>
        <h1>
            <asp:Label Text="" runat="server" ID="titleLabel" OnLoad="titleLabel_Load" />
        </h1>
        <div runat="server" id="groupPlaceHolder">
        </div>
    </LayoutTemplate>
    <GroupTemplate>
        <span>
            <div id="itemPlaceHolder" runat="server"></div>
        </span>
    </GroupTemplate>
    <ItemTemplate>
        <asp:ImageButton ID="itemImageButton" runat="server"
            CommandArgument="<%# Container.DataItem %>"
            ImageUrl="<%# Container.DataItem %>" Width="320" Height="240"
            OnCommand="itemImageButton_Command" />
        <asp:LinkButton ID="deleteLinkButton" runat="server" CommandName="Remove"
            CommandArgument="<%# Container.DataItem %>" Text="Delete" Visible="false"
            OnLoad="deleteLinkButton_Load" />
    </ItemTemplate>
    <EmptyItemTemplate>
        <td />
    </EmptyItemTemplate>
    <EmptyDataTemplate>
        <h3>No images available</h3>
    </EmptyDataTemplate>
    <InsertItemTemplate>
        <p>
            <asp:Label Text="Please upload an image" runat="server" ID="imageUploadLabel" />
            <asp:FileUpload runat="server" ID="imageUpload" OnLoad="imageUpload_Load" />
            <asp:Button ID="uploadButton" Text="Upload" runat="server" />
        </p>
        <p>
            <asp:Label Text="" runat="server" ID="imageUploadStatusLabel" />
        </p>
    </InsertItemTemplate>
</asp:ListView>

以及代码隐藏文件中的所有代码

有关更多详细信息,您可以访问以下链接创建图像网格