我想知道是否可以以每行三个条目的方式显示ArrayList的结果?目前,我正在获取所有更正信息,但每条输入都在一条线上不方便。我需要应用某种样式,或者在创建ArrayList时可能需要一些额外的代码吗?
如何设置,如果条目是“主要”地址,它将显示在它自己的行上(每个用户只有一个主要地址)。所有其他地址都显示在主要地址下方,每行有3个条目(这些是送货地址)。
任何建议都表示赞赏!
这是设计师的观点:
<div class="addressBook">
<div class="entries">
<div class="entry">
<div class="caption">
<h2>Billing Address</h2>
</div>
<div class="address">
<asp:Localize ID="PrimaryAddress" runat="server" Text="Please update your billing address."></asp:Localize>
</div>
</div>
<div class="caption">
<h2>Shipping Address</h2>
</div>
<asp:Repeater ID="AddressList" runat="server">
<ItemTemplate>
<div class="entry">
<div class="address">
<asp:Literal ID="Address" runat="server" Text='<%#Container.DataItem.ToString().Trim() == ","? "Please fill in your primary address.":Container.DataItem.ToString() %>'></asp:Literal>
<br /><asp:Literal ID="Phone" runat="server" Text='<%# getInfo(AlwaysConvert.ToInt(Eval("AddressId"))) %>'></asp:Literal><br /><br />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
这是代码隐藏:
public partial class AddressBook : System.Web.UI.UserControl
{
private int _UserId;
private User _User;
protected void Page_Init(object sender, EventArgs e)
{
_UserId = AlwaysConvert.ToInt(Request.QueryString["UserId"]);
_User = UserDataSource.Load(_UserId);
BindAddressBook();
}
protected void BindAddressBook()
{
User user = _User;
if (user.PrimaryAddress.IsValid)
{
PrimaryAddress.Text = user.PrimaryAddress.ToString(true) + "<br />" + getInfo(user.PrimaryAddress.Id);
}
if (user.Addresses.Count > 1)
{
List<Address> shippingAddresses = new List<Address>();
shippingAddresses.AddRange(user.Addresses);
int billingIndex = shippingAddresses.IndexOf(user.PrimaryAddressId);
if (billingIndex > -1)
{
shippingAddresses.RemoveAt(billingIndex);
}
shippingAddresses.Sort("LastName");
AddressList.DataSource = shippingAddresses;
AddressList.DataBind();
}
else
{
AddressList.Visible = false;
}
}
}
答案 0 :(得分:1)
您可以尝试的一件事是将您的转发器包装在UL中,并将LI标签放在Repeater的ItemTemplate中。每个LI的CSS样式都是内联的,宽度为33%。这样每行可以给你3个。
<ul class="addresses">
<asp:Repeater ID="AddressList" runat="server">
<ItemTemplate>
<li class="address">
<asp:Literal ID="Address" runat="server" Text='<%#Container.DataItem.ToString().Trim() == ","? "Please fill in your primary address.":Container.DataItem.ToString() %>'></asp:Literal>
<br /><asp:Literal ID="Phone" runat="server" Text='<%# getInfo(AlwaysConvert.ToInt(Eval("AddressId"))) %>'></asp:Literal><br /><br />
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
CSS:
ul.addresses { width: 100%; margin: 0; padding: 0; }
ul.addresses li.address { width: 33%; display: inline; }