Tuesday, 23 December 2014

Show image in data controls from the database

  • Hello...friends today I will show you that how to display image in data controls like that datalist,repeater.
  • First We make data table. Name:- images      Field Name:- image, name.
  • And now we take a control like as Repeater control.
  • We are take itemtemplet tag in repeater.
  • And then you can put image and label control in itemtemplet tag. Let we see it.
  • We write this code in repeater control's Source code.

<asp:Repeater ID="Repeater1" runat="server">

 <ItemTemplate>

  <table class="auto-style1">

   <tr>

    <td>

     <asp:Image ID="Image1" runat="server" Width="150px" Height="100" ImageUrl='<%#Eval("image") %>'/>

    </td>

   </tr>

   <tr>

    <td class="auto-style4">

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

    </td>

   </tr>

  </table>

 </ItemTemplate>

</asp:Repeater>

Get Full Example



  • After then We write code of displaying image from DB.
  • We write a namespace.
using System.Data.SqlClient; //use this in namespace in both version.

using System.Data; //not requerd to use this namespace in Visual Studo 2008.

  • We write an Object.
SqlConnection conn = new SqlConnection(@"path of the database/query string "); //for create a connection.

SqlCommand cmd; //interecting with the database means take the action in database like ad insert, update, delete. no required in log in program.

SqlDataAdapter adp; // read the data from the database. ,always take this object wheneve establist the connection

DataTable dt;
  • We write a displaying code in page load Object.
conn.Open();adp = new SqlDataAdapter("select * from imgupload", conn); dt = new DataTable();
dt = new DataTable();
adp.Fill(dt);
Repeater1.DataSource=dt;
Repeater1.DataBind();
conn.Close();

  • Now Your Program is ready to run.

if You any Query in php or get Example of php click on :- PHP EXAMLE

No comments:

Post a Comment

Show image in data controls from the database

Hello...friends today I will show you that how to display image in data controls like that datalist,repeater. First We make data table. N...