DataList Example in ASP.NET using C#

Data List is mainly used for the repeatation your data in row as well as column wise but the pagging is very difficult in datalist control but the other control List View is use as a same way of Datalist Here is The Real and Live Example of DataList :-

STEP BY STEP Suggestion :

  1. First You Can Start Your Visual Studio What Ever you have then go to     File->New->Website.
  2. Then Select Aspx Page And Give The Name Posting.aspx or What Ever You Are.
  3. In This Example We can Put Our Data in The Column Wisr or Row Wise As well and we can use SQLDataSource for Binding The Data With The DataBase.
  4.  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.


    POSTING.ASPX(DESIGN PAGE)



    POSTING.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:



No comments:

Post a Comment