Display record from Database in ASP.Net Repeater horizontally using C# and VB.Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago

I wanted to show the latest news horizontally like below image using Repeater.

Last time i displayed the news vertically by using datalist.

can we display the latest news horizontally by using Repeater?

if yes, can anyone provide me the sample code?

Posted 7 months ago Modified on 7 months ago

Hey chetan,

As you are looking for showing data in horizontally so for that use DataList, it's not possible in Repeater.

And getting latest date of news so use OrderBy in your query with column name which column you want to sort.


For this sample I have used of NorthWind database that you can download using the link given below.

Download Northwind Database


<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="3">
        <div style="border: 2px solid #ccc;">
            <b>Last Name:</b>
            <asp:Label ID="Label1" Text='<%# Eval("LastName") %>' runat="server" />
            <br />
            <b>First Name:</b>
            <asp:Label ID="Label2" Text='<%# Eval("FirstName") %>' runat="server" />
            <br />
            <b>Birth Date:</b>
            <asp:Label Text='<%#Eval("BirthDate","{0:dd/MM/yyyy}") %>' runat="server" />
            <br />



using System.Data;
using System.Data.SqlClient;
using System.Configuration;


Imports System.Data.SqlClient
Imports System.Data



protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        string strconstr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(strconstr))
            using (SqlCommand cmd = new SqlCommand("SELECT LastName, FirstName,BirthDate FROM Employees ORDER BY BirthDate DESC", con))
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    using (DataTable dt = new DataTable())
                        DataList1.DataSource = dt;


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim strconstr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As SqlConnection = New SqlConnection(strconstr)
            Using cmd As SqlCommand = New SqlCommand("SELECT LastName, FirstName,BirthDate FROM Employees ORDER BY BirthDate DESC", con)
                Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
                    Using dt As DataTable = New DataTable()
                        DataList1.DataSource = dt
                    End Using
                End Using
            End Using
        End Using
    End If
End Sub