Introduction
In this article, we will walk through the process of creating dynamically loading cards that pull content from your database and display it in a neat two-column layout. This is an efficient way to present feature-based content while maintaining a clean and SEO-friendly user interface.
Objective
Our goal is to display articles in dynamically generated cards that are styled in a way that offers a great user experience, improves SEO, and is easy to maintain. Each article will contain a title, description, icon, and an SEO-friendly URL.
Key Features
SEO-friendly URLs: Each article will have a clean, readable URL.
Dynamic Loading: Articles are loaded from the database in real-time.
Left and Right Column Layout: Articles will be grouped into pairs, displayed in two columns.
Alternating Background Colors: Grey backgrounds will alternate for visual appeal.
Handling Odd Number of Articles: If there is an odd number of articles, the last row will only contain a left card.
Components Used
ASP.NET Repeater Control: Used to display the articles dynamically.
Database Query: A SQL query is used to fetch active articles from the database.
CSS Styling: Custom styles are applied to alternate the background colors for left and right cards.
Step-by-Step Implementation
1. ASP.NET Repeater Control
The Repeater control is responsible for displaying each article. We create a dynamic structure using ItemTemplate, which allows us to render each article's content into styled cards.
<asp:Repeater ID="rptFeatures" runat="server">
<ItemTemplate>
<div class="col-sm-12 col-xs-12 nopad">
<!-- LEFT CARD -->
<div class='col-sm-6 col-xs-12 nopad <%# GetLeftStyle(Container.ItemIndex) %>'>
<div class="abc">
<div class="col-sm-2 col-xs-3 nopad top_pd">
<div class='product-icon <%# Eval("Left.Icon") %>'></div>
</div>
<div class="col-sm-10 col-xs-8 nopad">
<div class="heads_h2 heads_h2_resp"><%# Eval("Left.Heading") %></div>
<p class="paras paras_resp"><%# Eval("Left.Summary") %></p>
<div class="button read_more">
<a href='<%# Eval("Left.Link") %>'>Read APIs <span class="font_aws"></span></a>
</div>
<div class="blnk_sp"> </div>
</div>
</div>
</div>
<!-- RIGHT CARD -->
<asp:Panel runat="server" Visible='<%# Eval("Right") != null %>'>
<div class='col-sm-6 col-xs-12 nopad <%# GetRightStyle(Container.ItemIndex) %>'>
<div class="abc">
<div class="col-sm-2 col-xs-3 nopad top_pd">
<div class='product-icon <%# Eval("Right.Icon") %>'></div>
</div>
<div class="col-sm-10 col-xs-8 nopad">
<div class="heads_h2 heads_h2_resp"><%# Eval("Right.Heading") %></div>
<p class="paras paras_resp"><%# Eval("Right.Summary") %></p>
<div class="button read_more">
<a href='<%# Eval("Right.Link") %>'>Read APIs <span class="font_aws"></span></a>
</div>
<div class="blnk_sp"> </div>
</div>
</div>
</div>
</asp:Panel>
</div>
</ItemTemplate>
</asp:Repeater>

Join the conversation! Your thoughts help the community grow.