Customizing the Appearance of the DataList Control
We may customize the appearance of the DataList control by setting the style properties for the different parts of the control.
- AlternatingItemStyle: It specifies the style for alternating items in the DataList control.
- EditItemStyle: It defines the style for the item being edited in the DataList control.
- EditStyle: We use it to apply styles to an EditItemTemplate.
- FooterStyle: It specifies the style for the footer in the DataList control.
- HeaderStyle: It defines the style for the header in the DataList control.
- ItemStyle: It defines the style for the items in the DataList control.
- SelectedItemStyle: It represents the style for the selected item in the DataList control.
- SeparatorStyle: It specifies the style for the separator between the items in the DataList.
You can show or hide different control elements using the properties listed below:
- ShowFooter: Shows or hides the footer section of the DataList control.
- ShowHeader: Shows or hides the header section of the DataList control.
ASP.NET DataList Example
Here is an example of a working code of ASP.NET Datalist.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataListExample.aspx.cs"
Inherits="DataListExample.DataListExample" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>ASP.NET DataList Example of DataTable</p>
</div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table cellpadding="2" cellspacing="0" border="1" style="width: 200px; height: 100px;
border: dashed 2px #04b0ef; background-color: #fffffffa">
<tr>
<td>
<b>ID: </b><span class="idSpan"><%# Eval("ID") %></span><br />
<b>Name: </b><span class="nameSpan"><%# Eval("Name") %></span><br />
<b>Email: </b><span class="emailSpan"><%# Eval("Email")%></span><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</form>
</body>
</html>
Code Behind:
// DataListExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DataListExample
{
public partial class DataListExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("ID");
table.Columns.Add("Name");
table.Columns.Add("Email");
table.Rows.Add("420", "Charlie Chaplin", "Charlie@Chaplin.com");
DataList1.DataSource = table;
DataList1.DataBind();
}
}
}
Output:

FAQs
-
What is ASP.NET?
ASP.NET is an open-source, server-side web development framework designed to produce dynamic web pages. Microsoft developed it to allow programmers to build active websites, applications, and services.
-
What is ASP.NET in C#?
ASP.NET is a web-based application framework developed and marketed by Microsoft to let programmers build dynamic websites. It will enable you to use a full-featured programming language such as C# or VB.NET to build web applications quickly.
-
What is the difference between ASP.NET and C#?
The difference between ASP.NET and C# is that ASP.NET is an open-source framework for web application development to create dynamic content over web pages. C# is an object-oriented, functional, generic, imperative, and component-based programming language.
-
What is an ASP.NET DataList?
The ASP.NET DataList control is a lightweight server-side control that works as a container for data items. We use it to display data into a list structure to the web pages. It shows data from the data source that is either a DataTable or a table from a database.
-
What are data list controls?
We use the ASP.NET DataList control to display a repeated list of items bound to the control. However, by default, the DataList control adds a table around the data items. The DataList control may be attached to a database table, an XML file, or another list of things.
Key Takeaways
This article teaches about ASP.NET DataList and how we use them. We saw why ASP.Net DataList could be beneficial for a developer to learn.
Click here to read about the Top 10 web development frameworks. Click here to see other related blogs on Features Of ASP Net. Check out our Web development course and blogs on Backend Web Technologies.
If you are preparing for your DSA interviews then, Coding Ninjas Studio is a one-stop destination. This platform will help you acquire effective coding techniques and overview student interview experience in various product-based companies.
Happy Learning!