DataList Example in ASP.NET using C#


Posted in : ASP.Net Posted on : December 3, 2010 at 6:10 PM Comments : [ 0 ]
Advertisements
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" 
AutoEventWireup="true"
CodeFile="DataList.aspx.cs" Inherits="DataList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<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" 
DataSourceID="SqlDataSource1"
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" />
<HeaderTemplate>
Student Information
</HeaderTemplate>
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' 
ForeColor="#000099" />
<br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
Age:
<asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("Age") %>' />
<br />
Course:
<asp:Label ID="CourseLabel" runat="server" Text='<%# Eval("Course") %>' />
<br />
Branch:
<asp:Label ID="BranchLabel" runat="server" Text='<%# Eval("Branch") %>' />
<br />
City:
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
<br />
MobileNo:
<asp:Label ID="MobileNoLabel" runat="server" Text='<%# Eval("MobileNo") %>' />
<br />
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" 
SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
<br />
</div>
</asp:Content>

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


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