从数据库中查看GridView中的图像

时间:2015-10-30 18:05:29

标签: c# asp.net gridview visual-studio-2013

我有三列的网格视图,我只需要制作照片库,我从数据库中提取图像

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

问题是相同的照片在列中出现三次,我希望它在每列中逐个更改 我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

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

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

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

有关详细信息,请点击以下链接 create an image grid