Bind Image In GridView Using C# With ASP.NET

In a case of using image uploading and downloading from the database, the following sample will help you.

In cases of using image uploading and downloading from the database, the following sample will help you.

Download the sample and change the connection string, and then it will work.

If you want to really have a data-bound GridViewImageColumn, the column in the database should contain the actual images. Since, the column in your database contains only the paths to the images: 

  1. ADD
  2. UPLOAD
  3. VIEW 
  4. REMOVE CATEGORY

Description

BIND THE IMAGE IN GRIDVIEW

This application is developed to Bind and view the images in the grid along with their details. Here, we can add the category name which specifies under which image the details will be bound. In upload category, Specify the name and description, Select the category under which you wish to upload the Image; choose the file path and bind. Further, view the image with its name and category in View category. Remove category will delete the entire category.

ASP.NET

  1. <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"     
  2.               AutoGenerateColumns="false" >   
  3.            <AlternatingRowStyle BackColor="White" />   
  4.            <Columns>   
  5.                <asp:TemplateField HeaderText="Image Name">   
  6.                       
  7.                    <ItemTemplate>   
  8.                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("ImgName")%>'></asp:Label>   
  9.                    </ItemTemplate>   
  10.                </asp:TemplateField>   
  11.                <asp:TemplateField HeaderText="Image Description" >   
  12.                       
  13.                    <ItemTemplate>   
  14.                        <asp:Label ID="Label2" runat="server" Text='<%#Eval("ImgDesc")%>' Width="200"></asp:Label>   
  15.                    </ItemTemplate>   
  16.                </asp:TemplateField>   
  17.                <asp:TemplateField HeaderText="Image">   
  18.                       
  19.                    <ItemTemplate>   
  20.                        <asp:Image ID="Image1" runat="server" Width="150" Height="100" ImageUrl='<%#Eval("ImgPath")%>'/>   
  21.                        <asp:Label ID="Label3" runat="server"></asp:Label>   
  22.                    </ItemTemplate>   
  23.                </asp:TemplateField>   
  24.            </Columns>   
  25.            <EditRowStyle BackColor="#2461BF" />   
  26.            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />   
  27.            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />   
  28.            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />   
  29.            <RowStyle BackColor="#EFF3FB" />   
  30.            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />   
  31.            <SortedAscendingCellStyle BackColor="#F5F7FB" />   
  32.            <SortedAscendingHeaderStyle BackColor="#6D95E1" />   
  33.            <SortedDescendingCellStyle BackColor="#E9EBEF" />   
  34.            <SortedDescendingHeaderStyle BackColor="#4870BE" />   
  35.     </asp:GridView>  
  • bindCategory.sql
  • BindImage.sql

ASP.NET