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 : Jana
Address : Gobi
Phone : 9876543234
City : Tamilnadu
|||
Name : Jay
Address : Surat
Phone : 888 555 2929
City : Surat
|||
Name : JK
Address :
Phone :
City :
|||
Name : k
Address : k
Phone : k
City : k
|||
Name : kjhg2
Address : jhg
Phone : 7654321
City : kjhgfd
|||
Name : lk
Address : klk
Phone : 5677
City : jj
|||
Name : mm
Address : n
Phone : k,lk,
City : nmn
|||
Name : qwertyuio
Address : 1qaz2wsx3edc
Phone : 9638527410
City : sdfgh
|||
Name : wfwfcasca
Address : cce
Phone : 1234567876543234567654
City : sdwfqwrferferfe
|||
Name : wwf
Address : sd
Phone : sd
City : sd
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>