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 : aassdd
Address : rtetyj
Phone : tiurku
City : trttyrt
|||
Name : Ahmad Alzahrani
Address : Alsulaimanyah
Phone : +ddddddd
City : Jeddah
|||
Name : arpit
Address : nag
Phone : 9574966121
City : dgm
|||
Name : as
Address : sd
Phone : sd
City : dfds
|||
Name : asd
Address : asda
Phone : adsa
City : adsa
|||
Name : asdfs
Address : asdf
Phone : asdf
City : adf
|||
Name : Beb
Address : Jeje kg
Phone : 73737373737
City : Sbbdbdbd
|||
Name : dfgdfg
Address : sfsdf
Phone : dfgdfg
City : erer
|||
Name : ewrr
Address : Philippines
Phone : ewrwrw
City : ew
|||
Name : ewrr
Address : wer
Phone : ewrwrwerw
City : rew
|||
Name : Fatteh
Address : F
Phone : Yyy
City : Uuuu
|||
Name : Fff
Address : Fff
Phone : Yyyy
City : Ttt
|||
Name : Hasim
Address : Kadi
Phone : 8989909012
City : Kadi
|||
Name : John Do
Address : 111 Clarion dr.
Phone : 213-333-3333
City : Torrancd
|||
Name : khan
Address : mandna
Phone : 024875294872
City : bannu
|||
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 : Priyesh
Address : delhi
Phone : 1223455744
City : Delhi south
|||
Name : Ramesh
Address : Palanpur
Phone : 7676767676
City : Palanpur
|||
Name : sd
Address : sds
Phone : sds
City :
|||
Name : sd
Address : sdf
Phone : 2422442
City : wer
|||
Name : sdfds
Address : sfdsf
Phone : sdfsdf
City : sdfs
|||
Name : sfdgh
Address : njyhbtgv
Phone : 7654
City : ujnyhbtg
|||
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 : Tsedup
Address : Aruwari
Phone : 9841277311
City : Kathmandu
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>