Coding Villa

Display Images using Database in Asp.Net 3.5

Author : Iram Irshad

Share with Friends
Views : 2159
Ratings : 0
Bookmarks : 0
Farourities : 0


This simple article contains step by step procedure for displaying images using database in Asp.Net 3.5.




Display Images Using Database:


In ASP.NET you can display images using database. That task can be performed through different controls. However, I have used a DataList and a SqlDataSource for that purpose. Following is the step by step procedure for doing that task.


Step1: Create a table in Sql server 2008 and imageid, Title and Picture fields in that table. In the Picture field store URL of images that you want to display.


Step2: Drag a DataList and a SqlDataSource control on your .aspx page.


Step3: Now bind the Datalist to that Sql data Source. You can bind it either through code view of .aspx page or through design view. Now your code at .aspx page will be like below.


<form id="form1" runat="server"> 

  <div align="center" class="pageHeading">

            Display Image From Database

          <br />

   <asp:DataList ID="DataList1" runat="server"


            RepeatColumns="3" Height="192px">


                <br />

              //bind Picture field of the data source using HTML <img> tag

       <img id="Picture" runat="server" src='<%# Eval("Picture") %>'/>

                <br />

       <asp:Label ID="Label1" runat="server" Text='<%# Eval("Title") %>' />

                <br />

                <br />




      <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:ProductsConnectionString %>"

        SelectCommand="SELECT [Title], [Picture] FROM [Images]"></asp:SqlDataSource>





Article Tags
Share with Friends


Leave a Reply

Name (required)  
Mail (will not be published) (required)   
Enter This Code


Article Categories



Mobile Development

Operating Systems

Web Development

Coding Villa on Facebook