以SQL SERVER2000自带数据库Northwind中Customers表示例. 前台aspx代以码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Repeater.aspx.cs" Inherits="Repeater" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Repeater控件使用</title> <script language="javascript" type="text/javascript"> function Check(parentChk,ChildId) { var oElements = document.getElementsByTagName("INPUT"); var bIsChecked = parentChk.checked; for(i=0; i<oElements.length;i++) { if( IsCheckBox(oElements[i]) && IsMatch(oElements[i].id, ChildId)) { oElements[i].checked = bIsChecked; } } } function IsMatch(id, ChildId) { var sPattern =’^Repeater1.*’+ChildId+’$'; var oRegExp = new RegExp(sPattern); if(oRegExp.exec(id)) return true; else return false; } function IsCheckBox(chk) { if(chk.type == 'checkbox') return true; else return false; } </script> </head> <body> <form id="form1" runat="server"> <div style="margin-bottom:20px;text-align:center; width:1006px;">Repeater控件使用</div> <asp:Repeater ID="Repeater1" runat="server"> <%--SeparatorTemplate描述一个介于每条记录之间的分隔符--%> <%--<SeparatorTemplate> <tr> <td colspan="5"><hr /></td> </tr> </SeparatorTemplate>--%> <HeaderTemplate> <table border="1" cellpadding="0" cellspacing="0" style="width:1006px;border-collapse:collapse; text-align:center;"> <tr> <td style="background-color:#cccccc; font-weight:bold; height:25px;"><input id="chkAll" name="chkAll" runat="server" type="checkbox" onclick="Check(this,’chkItem')" title="全选" />全</td> <td style="background-color:#cccccc; font-weight:bold; height:25px;">View</td> <td style="background-color:#cccccc; font-weight:bold; height:25px;">CustomerID</td> <td style="background-color:#cccccc; font-weight:bold;">CompanyName</td> <td style="background-color:#cccccc; font-weight:bold;">ContactName</td> <td style="background-color:#cccccc; font-weight:bold;">ContactTitle</td> <td style="background-color:#cccccc; font-weight:bold;">Address</td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><asp:CheckBox ID="chkItem" runat="server" /></td> <td><a href='<%# "View.aspx?id="+DataBinder.Eval(Container.DataItem, "CustomerID") %>' target="_blank">View</a></td> <td><asp:Label ID="lblID" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID")%>' runat="server"></asp:Label></td> <td><%# DataBinder.Eval(Container.DataItem, "CompanyName")%></td> <td><%# DataBinder.Eval(Container.DataItem, "ContactName")%></td> <td><%# DataBinder.Eval(Container.DataItem, "ContactTitle")%></td> <td><%# DataBinder.Eval(Container.DataItem, "Address")%></td> </tr> </ItemTemplate> <%--AlternatingItemTemplate描述交替输出行的另一种外观--%> <AlternatingItemTemplate> <tr bgcolor="#e8e8e8"> <td><asp:CheckBox ID="chkItem" runat="server" /></td> <td><a href='<%# "View.aspx?id="+DataBinder.Eval(Container.DataItem, "CustomerID") %>' target="_blank">View</a></td> <td><asp:Label ID="lblID" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID")%>' runat="server"></asp:Label></td> <td><%# DataBinder.Eval(Container.DataItem, "CompanyName")%></td> <td><%# DataBinder.Eval(Container.DataItem, "ContactName")%></td> <td><%# DataBinder.Eval(Container.DataItem, "ContactTitle")%></td> <td><%# DataBinder.Eval(Container.DataItem, "Address")%></td> </tr> </AlternatingItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <div style="background-color:#dedede; width:1006px;"> […]
View Details