CSharp Asp:Datalist: Repeat Column, Repeat Directions, Gridlines, – ADO.Net Database

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Not IsPostBack Then
        Dim DBConn as OleDbConnection
        Dim DBCommand As OleDbDataAdapter
        Dim DSPageData as New DataSet
        DBConn = New OleDbConnection( _
            "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
            & "DATA SOURCE=" _
            & Server.MapPath("EmployeeDatabase.mdb;"))
        DBCommand = New OleDbDataAdapter _
            ("Select FirstName, LastName " _
            & "From Employee " _
            & "Order By FirstName", DBConn)
        DBCommand.Fill(DSPageData, _
            "Employee")
        dlDepts.DataSource = _
            DSPageData.Tables("Employee").DefaultView
        dlDepts.DataBind()
    End If
End Sub
</script>
<html>
<head>
<title>Creating a Basic DataList Control</title>
</head>
<body LEFTMARGIN="40">
<form runat="server">
<br /><br />
<asp:datalist
    id="dlDepts"
    runat="server"
    repeatcolumns=2
    repeatdirection="Vertical"
    repeatlayout="table"
    gridlines="Both"
    backcolor="lightyellow"
    forecolor="darkred"
    borderwidth=3
    bordercolor="darkgreen"
>
    <headerstyle
        backcolor="darkred"
        forecolor="lightyellow"
        font-bold="true"
    />
    <headertemplate>
        Below is a list of all the employees.
    </headertemplate>
    <itemtemplate>
        <%# "<b>Department:</b> " _
            & DataBinder.Eval(Container.DataItem, "FirstName") _
            & "<br />" _
            & DataBinder.Eval(Container.DataItem, "LastName")
        %>
    </itemtemplate>
    <alternatingitemstyle
        backcolor="lightgreen"
        forecolor="darkblue"
    />
    <alternatingitemtemplate>
        <%# "<b>Department:</b> " _
            & DataBinder.Eval(Container.DataItem, "FirstName") _
            & "<br />" _
            & DataBinder.Eval(Container.DataItem, "LastName")
        %>
    </alternatingitemtemplate>
    <separatortemplate>
        ***
    </separatortemplate>
    <footerstyle
        backcolor="darkred"
        forecolor="lightyellow"
        font-bold="true"
    />
    <footertemplate>
        No more records found.
    </footertemplate>
</asp:datalist>
</form>
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.