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 :
Address :
Phone :
City :
|||
Name : 12
Address : 122
Phone : 112212
City : 112221
|||
Name : aaa
Address : aa
Phone : aaa
City : aa
|||
Name : aabid
Address : kharar
Phone : 7006175252
City : mohali
|||
Name : aassdd
Address : rtetyj
Phone : tiurku
City : trttyrt
|||
Name : amit
Address : delhi
Phone : 1223455744
City : Delhi south
|||
Name : bb
Address : jjh
Phone : bnb
City :
|||
Name : dfgdfg
Address : sfsdf
Phone : dfgdfg
City : erer
|||
Name : erf
Address : dasf
Phone : dsaas
City : asdaf
|||
Name : Fatteh
Address : F
Phone : Yyy
City : Uuuu
|||
Name : Fff
Address : Fff
Phone : Yyyy
City : Ttt
|||
Name : khan
Address : mandna
Phone : 024875294872
City : bannu
|||
Name : manish
Address : andhri
Phone : 1566666
City : mubai
|||
Name : manish
Address : andhri
Phone : 1566666
City : mubai
|||
Name : Ramesh
Address : Palanpur
Phone : 7676767676
City : Palanpur
|||
Name : sdfds
Address : sfdsf
Phone : sdfsdf
City : sdfs
|||
Name : sfdgh
Address : njyhbtgv
Phone : 7654
City : ujnyhbtg
|||
Name : test
Address : test
Phone : e
City : e
|||
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>