Data Bound Controls in ASP.Net - Part 2 (DataList control)

The DataList Web server control displays rows of database information in customized format. These two controls play an important role in ASP.NET. They represent many common features.


Here is a sample code for DataList. we see this code in detail later on.

ASP.Net Page Code:


<div>
        <h2 style="color: Green">
            DataList in ASP.NET using C#</h2>
        <asp:DataList ID="DataList1" runat="server" CssClass="Grid" DataSourceID="SqlDataSource1" 
                GridLines="Both" RepeatColumns="3" RepeatDirection="Horizontal" RepeatLayout="Table">
            
            <HeaderStyle  ForeColor="White" CssClass="HeaderStyle"/>
            <HeaderTemplate>
                Product Information
            </HeaderTemplate>
            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <ItemTemplate>
                ID:
                <asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("ProductID") %>' />
                <br />
                Prod:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("ProductName") %>' 
                    ForeColor="#000099" />
                <br />
                Price:
                <asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />
                <br />
                
                Stock:
                <asp:Label ID="CourseLabel" runat="server" Text='<%# Eval("UnitsInstock") %>' />
                <br />
                order:
                <asp:Label ID="BranchLabel" runat="server" Text='<%# Eval("UnitsOnOrder") %>' />
                <br />
                Reorder:
                <asp:Label ID="CityLabel" runat="server" Text='<%# Eval("ReOrderLevel") %>' />
                <br />
                Quantity:
                <asp:Label ID="MobileNoLabel" runat="server" Text='<%# Eval("QuantityPerUnit") %>' />
                <br />
                <br />
            </ItemTemplate>
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" 
            SelectCommand="SELECT top 11 * FROM [Products]"></asp:SqlDataSource>
        <br />
    </div>

Output:



DataList Layouts:

The DataList control uses an HTML table to lay out the rendering of items to which the template is applied. You can control the order, direction, and number of columns for the individual table cells used to render DataList items. The following table describes the layout options that are supported by the DataList control.




We will see more about DataList control and other ASP.Net Data Bound controls in more detail in next blogs. :)




Comments

Popular posts from this blog

Data Bound Controls in ASP.Net - Part 4 (FormView and DetailsView controls)

ASP.net: HttpHandlers

The Clickjacking attack and X-Frame-Options