DataList Example in ASP.NET using C#

DataList Example in ASP.NET using C#

Posted in : ASP.Net Posted on : December 3, 2010 at 6:10 PM Comments : [ 0 ]

In this article we will introduce with DataList control in ASP.NET using C#.

DataList Example in ASP.NET using C#

DataList Control in ASP.NET is used to display the data item in a repeating list. DataList optionally supports selecting and editing the items. In this example we use the DataList and bind the data with it. We use SQLDataSource for databinding. You can use the AutoFormat style which is shown in the following figure.

You can edit the template when you click on the special tag button of the datalist and click Edit Template. You can see the following figure.

DataList.aspx (Design Page):

DataList.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" 
CodeFile="DataList.aspx.cs" Inherits="DataList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<h2 style="color: Green">
DataList in ASP.NET using C#</h2>
<asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" 
Font-Bold="True" Font-Names="Verdana" Font-Size="Small" GridLines="Both" RepeatColumns="2"
RepeatDirection="Horizontal" Width="463px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" Font-Size="Large" ForeColor="White"
HorizontalAlign="Center" VerticalAlign="Middle" />
Student Information
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' 
ForeColor="#000099" />
<br />
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
<asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("Age") %>' />
<br />
<asp:Label ID="CourseLabel" runat="server" Text='<%# Eval("Course") %>' />
<br />
<asp:Label ID="BranchLabel" runat="server" Text='<%# Eval("Branch") %>' />
<br />
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
<br />
<asp:Label ID="MobileNoLabel" runat="server" Text='<%# Eval("MobileNo") %>' />
<br />
<br />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" 
SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
<br />


Download source code
Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics