欢迎光临

木子屋

标题: Repeater一行多列示例

作者: dnawo

日期: 2011-03-01 01:49 PM

分类: Web编程

内容: 复制内容到剪贴板 程序代码<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
int RepeatColumns = 3; //每行列数
int TotalColumns = 0; //计数器

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataList();
}
}
protected void DataList()
{
string[] lstUsers = { "user1", "user2", "user3", "user4", "user5" };
Repeater1.DataSource = lstUsers;
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
TotalColumns++;
if (TotalColumns % RepeatColumns == 0)
e.Item.Controls.Add(new LiteralControl("<br/>"));
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate><%# Container.DataItem %> </ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.109 ms

返回

标题: Repeater一行多列示例

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.109 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.188 ms

返回