ASP.NET Tutorial/ASP.net Controls/Repeater — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:00, 26 мая 2010
Bind data from Access database to an ASP:Repeater (VB.net)
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load(Sender as Object, e as EventArgs)
dim myConnection as new OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("EmployeeDatabase.mdb;"))
dim myCommand as new OleDbDataAdapter("select * from employee", myConnection)
dim ds as DataSet = new DataSet()
myCommand.Fill(ds, "employee")
Repeater1.DataSource = ds
Repeater1.DataMember = "employee"
DataBind()
end sub
</script>
<html><body>
<ASP:Repeater id="Repeater1" runat="server" >
<HeaderTemplate>
<tr>
<td width="200"><b>Name</b></td>
<td width="200"><b>ID</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# Container.DataItem("FirstName") %>
<%# Container.DataItem("LastName") %>
</td>
<td> <%# Container.DataItem("ID") %> </td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td>
<%# Container.DataItem("FirstName") %>
<%# Container.DataItem("LastName") %>
</td>
<td>
<%# Container.DataItem("ID") %>
</td>
</tr>
</AlternatingItemtemplate>
<SeparatorTemplate>
<tr>
<td colspan="2" align="center">
- - -
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</FooterTemplate>
</ASP:Repeater>
</body></html>
Repeater with Table
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Like a Grid</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<thead>
<td> <b>ID</b> </td>
<td> <b>First Name</b> </td>
<td> <b>Last Name</b> </td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="white">
<%# Eval("EmployeeID") %></td>
<td bgcolor="white">
<%# Eval("FirstName")%></td>
<td bgcolor="white">
<%# Eval("LastName") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td bgcolor="#eeeeee">
<%# Eval("EmployeeID") %></td>
<td bgcolor="#eeeeee">
<%# Eval("FirstName")%></td>
<td bgcolor="#eeeeee">
<%# Eval("LastName") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthWind %>"
SelectCommand="SELECT employeeid, firstname, lastname FROM employees">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>