怎么控制repeate中一行显示的个数
3个回答
展开全部
每5行折行
.aspx
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Eval("Name") %>
<asp:Label ID="Label1" runat="server" Text='<%# Container.ItemIndex % 5 == 4 ? "<br />" : string.Empty %>' ></asp:Label>
</ItemTemplate>
</asp:Repeater>
.aspx.cs
public partial class RepeaterLine : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
List<User> list = new List<User>();
list.Add(new User { Id = 1, Name = "aa" });
list.Add(new User { Id = 2, Name = "bb" });
list.Add(new User { Id = 3, Name = "cc" });
list.Add(new User { Id = 4, Name = "dd" });
list.Add(new User { Id = 5, Name = "ee" });
list.Add(new User { Id = 6, Name = "ff" });
Repeater1.DataSource = list;
Repeater1.DataBind();
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
.aspx
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Eval("Name") %>
<asp:Label ID="Label1" runat="server" Text='<%# Container.ItemIndex % 5 == 4 ? "<br />" : string.Empty %>' ></asp:Label>
</ItemTemplate>
</asp:Repeater>
.aspx.cs
public partial class RepeaterLine : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
List<User> list = new List<User>();
list.Add(new User { Id = 1, Name = "aa" });
list.Add(new User { Id = 2, Name = "bb" });
list.Add(new User { Id = 3, Name = "cc" });
list.Add(new User { Id = 4, Name = "dd" });
list.Add(new User { Id = 5, Name = "ee" });
list.Add(new User { Id = 6, Name = "ff" });
Repeater1.DataSource = list;
Repeater1.DataBind();
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
展开全部
有几个<ItemTemplate>列,就有几列。也就是每行显示的个数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果想控制一行显示多个,可以用DataList控件,Repeate控件只能用于每行显示一个,但是可以通过css来控制每行显示的个数
如果有什么不懂可以hi~我,给你写个例子
如果有什么不懂可以hi~我,给你写个例子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询