DataList多行数据后如何添加一条分隔线
类似
*******
*******
*******
*******
-------
*******
*******
*******
*******
-------
*******
*******
*******
*******
-------
方法一:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("1");
for (int i = 0; i < 20; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i.ToString();
dt.Rows.Add(dr);
}
this.DataList1.DataSource = dt;
this.DataList1.DataBind();
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemIndex + 1) % 4 == 0)
{
Literal lit = new Literal();
lit.Text = "<hr />";
e.Item.Controls.Add(lit);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%#Bind('1')%>"></asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
方法二:
<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
<br />
Age:
<asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("Age") %>' />
</ItemTemplate>
<SeparatorTemplate>
<hr style="border:dotted 1px #333; height:1px;" />
</SeparatorTemplate>
</asp:DataList>