Search
Author
ASP.NET Tutorials
Author
Sheo Narayan
Advertisements


Winners

Win Prizes

Social Presence
Like us on Facebook

Silverlight Tutorials | Report a Bug in the Tutorial
asp:DataList control
DataList control displays data using user-defined layout. However there are many added advantages in comparison with Repeater control in terms of graphical layout.
 
DataList control displays data using user-defined layout. However there are many added advantages in comparison with Repeater control in terms of graphical layout.

One of the main advantage of DataList control is it supports directional rendering (Horizontal/Vertical) also. It has many properties and several events attached. We can say DataList ias the advanced version of Repeater control.

Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of <table> tag.

Following are some important properties that are very useful.
AlternatingItemTemplate Template to define the rendering of every alternate item.
FooterTemplate Template to define how to render the footer.
HeaderTemplate Template to define how to render the header.
Items Gets the collection of DataList Items.
ItemTemplate Template to define how items are rendered.
SeparatorTemplate Template to define how separator between items will be rendered.
DEMO : DataList Show Source Code
Name :
Address :
Phone :
City :
|||
Name :
Address :
Phone :
City :
|||
Name : etwe
Address : ttetew
Phone : 897894654
City : surat
|||
Name : ewrr
Address : Philippines
Phone : ewrwrw
City : ew
|||
Name : ff
Address : ff
Phone : 878555555
City : yyy
|||
Name : Hasim
Address : Kadi
Phone : 8989909012
City : Kadi
|||
Name : hkhk
Address : hkhk
Phone : hkhk
City : hkhk
|||
Name : John Do
Address : 111 Clarion dr.
Phone : 213-333-3333
City : Torrancd
|||
Name : juj
Address : try
Phone : rtyr
City : rtyty
|||
Name : kemmy kalaria
Address : Gol residency ,nana muva ,main road rajkot
Phone : 09426977487
City : Rajkot
|||
Name : Kong Yoon Thim
Address : 23, Jalan SS8/8
Phone : +60122610084
City : Petaling Jaya
|||
Name : Kong Yoon Thim
Address : 23, Jalan SS8/8
Phone : +60122610084
City : Petaling Jaya
|||
Name : lukasz Michalak
Address : 1 maja 59/40
Phone : 533792647
City : lubartów
|||
Name : Name
Address : Address
Phone : Phone
City : City
|||
Name : Name
Address : Address
Phone : Phone
City : City
|||
Name : sd
Address : sdf
Phone : 2422442
City : wer
|||
Name : sss
Address : eee
Phone : 4555
City : nagpur
|||
Name : t
Address : t
Phone : 4453
City : t
|||
Name : test
Address : test
Phone : test
City : test
|||
Name : test
Address : test
Phone : 9999999
City : Singapore
|||
Name : Test
Address : 1002 Central Parkway South
Phone : 210-444-5655
City : San Diego
|||
Name : Try1
Address : #102, Above GK Provision Store
Phone : 9972412313
City : Bangalore
No records displaying or need more records? Try inserting records from FormView Control tutorial.
 
    

// DataList Control ////////////////////////////
<asp:DataList ID="DataList1" runat="Server" DataSourceID="SqlDataSource1" DataKeyField="AutoID" Width="100%"
     RepeatColumns="2" RepeatDirection="horizontal" RepeatLayout="table" CellPadding="2" CellSpacing="1"
     BorderWidth="1">
    <ItemTemplate>
        <table width="100%" style="background-color:#efefef;">
            <tr>
                <td>
                    Name : <%# Eval("Name") %><br />
                    Address : <%# Eval("Address") %><br />
                    Phone : <%# Eval("Phone") %><br />
                    City : <%# Eval("City") %><br />                                        
                </td>
            </tr>
        </table>
    </ItemTemplate>
    <AlternatingItemTemplate>
        <table width="100%">
            <tr>
                <td>
                    Name : <%# Eval("Name") %><br />
                    Address : <%# Eval("Address") %><br />
                    Phone : <%# Eval("Phone") %><br />
                    City : <%# Eval("City")% ><br />                                        
                </td>
            </tr>
        </table>
    </AlternatingItemTemplate>
    <SeparatorTemplate>
        |||
    </SeparatorTemplate>
</asp:DataList>    



// SqlDataSource Control ////////////////////////////                
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnStr %>'
 SelectCommand="Select * FROM SampleForTutorials ORDER BY [Name]">
 </asp:SqlDataSource>