ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display record from Database in ASP.Net Repeater horizontally using C# and VB.Net<p>Hey <a class="username" rel="chetan"> chetan</a>,</p> <p>As you are looking for showing data in horizontally so for that use DataList, it's not possible in Repeater.</p> <p>And getting latest date of news so use OrderBy in your query with column name which column you want to sort.</p> <p><span style="text-decoration: underline;"><strong>Database</strong></span></p> <p>For this sample I have used of NorthWind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-the-Northwind-and-Pubs-Sample-Databases-in-SQL-Server-Express.aspx" target="_blank">Download Northwind Database</a></p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:DataList ID=&#34;DataList1&#34; runat=&#34;server&#34; RepeatDirection=&#34;Horizontal&#34; RepeatColumns=&#34;3&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div style=&#34;border: 2px solid #ccc;&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b&gt;Last Name:&lt;/b&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;Label1&#34; Text=&#39;&lt;%# Eval(&#34;LastName&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b&gt;First Name:&lt;/b&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;Label2&#34; Text=&#39;&lt;%# Eval(&#34;FirstName&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b&gt;Birth Date:&lt;/b&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label Text=&#39;&lt;%#Eval(&#34;BirthDate&#34;,&#34;{0:dd/MM/yyyy}&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt; &nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strconstr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(strconstr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT LastName, FirstName,BirthDate FROM Employees ORDER BY BirthDate DESC&#34;, con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { using (DataTable dt = new DataTable()) { da.Fill(dt); DataList1.DataSource = dt; DataList1.DataBind(); } } } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">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(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(strconstr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT LastName, FirstName,BirthDate FROM Employees ORDER BY BirthDate DESC&#34;, con) Using da As SqlDataAdapter = New SqlDataAdapter(cmd) Using dt As DataTable = New DataTable() da.Fill(dt) DataList1.DataSource = dt DataList1.DataBind() End Using End Using End Using End Using End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/qVsAOMf.jpg" alt="" width="459" height="212" /></p>https://www.aspforums.net:443/Threads/174878/Display-record-from-Database-in-ASPNet-Repeater-horizontally-using-C-and-VBNet/https://www.aspforums.net:443/Threads/174878/Display-record-from-Database-in-ASPNet-Repeater-horizontally-using-C-and-VBNet/Wed, 12 Dec 2018 00:42:51 GMT