In this article I’m going to explain how to display images in DataList control using ASP.NET with C#.

If you want to highlight DataList item on mouseover you could refer this article.

            How to highlight DataList item on mouseover using ASP.NET with C#

What is DataList .?

          The DataList Web server control displays data in a format that you can define using templates and styles. The DataList control is useful for data in any repeating structure, such as a table. The DataList control can display rows in different layouts, such as ordering them in columns or rows.     

          Here I’ll show you how to display images in DataList control to display employee details by repeating structure such as table.

          I have used Northwind database to display employee details. Here you can download Northwind database

http://northwinddatabase.codeplex.com/releases/view/71634

Table design:

Column Name

Data type

FirstName

varchar(100)

Title

varchar(100)

City

varchar(50)

Country

varchar(50)

PhotoPath

varchar(50)

 

Designer source code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

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

    <div>

        <asp:DataList ID="DataList1" runat="server" BackColor="Gray" BorderColor="#666666"

            BorderStyle="None" BorderWidth="2px" CellPadding="3" CellSpacing="2"

            Font-Names="Verdana" Font-Size="Small" GridLines="Both" RepeatColumns="3" RepeatDirection="Horizontal"

            Width="600px">

            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

            <HeaderStyle BackColor="#333333" Font-Bold="True" Font-Size="Large" ForeColor="White"

                HorizontalAlign="Center" VerticalAlign="Middle" />

            <HeaderTemplate>

                Employee Details</HeaderTemplate>

            <ItemStyle BackColor="White" ForeColor="Black" BorderWidth="2px" />

            <ItemTemplate>

                <asp:Image ID="imgEmp" runat="server" Width="100px" Height="120px" ImageUrl='<%# Bind("PhotoPath", "~/photo/{0}") %>' style="padding-left:40px"/><br />

                <b>Employee Name:</b>

                <asp:Label ID="lblCName" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>

                <br />

                <b>Designation:</b>

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

                <br />

               <b> City:</b>

                <asp:Label ID="lblCity" runat="server" Text=' <%# Bind("City") %>'></asp:Label>

                <br />

                <b>Country:</b>

                <asp:Label ID="lblCountry" runat="server" Text='<%# Bind("Country") %>'></asp:Label>

                <br />

            </ItemTemplate>

        </asp:DataList>

    </div>  

    </form>

</body>

</html>

  

Code behind:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient; 

public partial class _Default : System.Web.UI.Page

{

    SqlConnection conn = new SqlConnection("Data Source=SPIDER;Initial Catalog=Northwind;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            BindData();

        }

    }

    protected void BindData()

    {

        DataSet ds = new DataSet();

        conn.Open();

        string cmdstr = "Select top 6 * from Employees";

        SqlCommand cmd = new SqlCommand(cmdstr, conn);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);

        adp.Fill(ds);   

        DataList1.DataSource = ds.Tables[0];

        DataList1.DataBind();      

    }

}

 

 

cytotec abortion

an abortion pill buy abortion pills online
medical abortion pill online abortion pill abortion pill


View demo Download
http://www.dotnetfox.com/Document/1037/0photo1.jpg

If you enjoyed this article, get email updates (it's free).


Related Articles
  • How to use DataList control in ASP.NET using C#The DataList Web server control displays data in a format that you can define using templates and styles. The DataList control is useful for data in any repeating structure, such as a table. The DataList control can display rows in different layouts, such as ordering them in columns or rows.
  • How to display images in DataList control using ASP.NET with C#In this article I’m going to explain how to display images in DataList control using ASP.NET with C#. The DataList Web server control displays data in a format that you can define using templates and styles. The DataList control is useful for data in any repeating structure, such as a table. The DataList control can display rows in different layouts, such as ordering them in columns or rows.
  • How to bind DataList from XML file in ASP.NET using C#In this article I’m going to explain how to bind DataList from XML file in ASP.NET using C#. The DataList Web server control displays data in a format that you can define using templates and styles. The DataList control is useful for data in any repeating structure, such as a table. The DataList control can display rows in different layouts, such as ordering them in columns or rows.
  • How to highlight DataList item on mouseover using ASP.NET with C#In this article I’m going to explain how to highlight DataList itemon mouseover using ASP.NET with C#. The DataList Web server control displays data in a format that you can define using templates and styles. The DataList control is useful for data in any repeating structure, such as a table. The DataList control can display rows in different layouts, such as ordering them in columns or rows.

Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox