Search

Thursday, December 4, 2014
0 comments

How to retrieve images from database table in ASP.NET

6:39 AMThursday, December 4, 2014
Database is a storage system, through which we can store data permanently into the secondary storage device. Similar to programming languages, database also take some data types for categorize data. like int, Text, DateTime etc. Now, we will discussed on image. In this example we will retrieve images from database. First we store images into database, actually images is not stored directly, so for that path of the images is stored into the database. Now, bind the GridView with the image field.  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" Width="280px">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                <asp:ImageField DataImageUrlField="imagepath" HeaderText="Image">
                    <ControlStyle Height="200px" Width="200px" />
                </asp:ImageField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [imagetable]"></asp:SqlDataSource>
    </form>
</body>
</html>
Code Generate the following output

How to retrieve images from database table in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top