Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Tuesday, March 28, 2006

Using RepeatDirection and RepeatColumn Properties of a DataList (Chapter 3)

In this example, our objective is to display the product’s data in a fashion as shown in Figure 3.72. A data table in a data set is essentially a relational databaselike table in the computer’s cache. It has rows (records) and columns (fields) of data extracted from the database.When we bind a ListControl to a data table, each record of the data table becomes an Item in the ItemList collection of the ListControl. In this particular example, we want to display three of these Items in each row of our display (horizontally).This is why we have defined the DataControl as follows:
<asp:DataList id="dataList1" border=0
RepeatDirection="Horizontal" RepeatColumns="3" runat="server">
The remainder of the code for this application, as shown in Figure 3.73, is straightforward.
Figure 3.72 Displaying Data Using RepeatDirection and RepeatColumn Properties

Figure 3.73 Listing of DataList1.aspx
<!— Chapter3\DataList1.aspx —>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html><head></head>
<script language="VB" Debug="true" runat="server">
Sub Page_Load(src As Object, e As EventArgs)
If Not IsPostBack Then
bindListControl
End If
End Sub
Sub bindListControl()
Dim myConn As OleDbConnection
Dim myOleDbAdapter As OleDbDataAdapter
Dim connStr, sqlStr As String
Dim myDataSet As New Dataset
connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Products.mdb"
sqlStr="SELECT ProductId, ProductName, Price, ImagePath " _
+ "FROM Products ORDER BY Price"
myConn= New OleDbConnection(connStr)
myConn.Open()
myOleDbAdapter =New OleDbDataAdapter(sqlStr,myConn)
myOleDbAdapter.Fill(myDataSet,"dtProducts")
dataList1.DataSource=myDataSet.Tables("dtProducts")
dataList1.DataBind()
End Sub
</script>
<body bgcolor="white">
<asp:DataList id="dataList1" border=0
RepeatDirection="Horizontal" RepeatColumns="3" runat="server">
<ItemTemplate><table><tr>
<td> <asp:Image height=80 width=80
ImageURL='<%# Container.DataItem("ImagePath") %>'
runat="server" />
</td></tr><tr>
<td> Product ID:
<%# Container.DataItem("ProductId")%><br>
Description:<b><i><%# Container.DataItem("ProductName")%>
</b></i><br><b>Unit Price: $
<%# Container.DataItem("Price")%></b><br>
</td></tr></table>
</ItemTemplate>
</asp:DataList></body></html>

0 Comments:

Post a Comment

<< Home