日期:2014-05-20  浏览次数:20555 次

reperat数据呈现两列
用li   列表显示

------解决方案--------------------
<asp:Repeater runat= "server " ID= "rep " OnItemCreated= "rep_ItemCreated ">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<td> aaa </td>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

protected void rep_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) {
if (e.Item.ItemIndex % 2 == 0)
{
LiteralControl li = e.Item.Controls[0] as LiteralControl;
li.Text = " <tr> " + li.Text;
}
else {
LiteralControl li = e.Item.Controls[0] as LiteralControl;
li.Text += " </tr> ";
}
//没有考虑到最后一行的补齐 ,自己加完了,好运

}
}
------解决方案--------------------
少了tr

<asp:Repeater runat= "server " ID= "rep " OnItemCreated= "rep_ItemCreated ">
<HeaderTemplate>
<table> <tr>
</HeaderTemplate>
<ItemTemplate>
<td> aaa </td>
</ItemTemplate>
<FooterTemplate>
</tr> </table>
</FooterTemplate>
</asp:Repeater>

protected void rep_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) {
if (e.Item.ItemIndex % 2 == 0)
{
LiteralControl li = e.Item.Controls[0] as LiteralControl;
li.Text = " <tr> " + li.Text;
}
else {
LiteralControl li = e.Item.Controls[0] as LiteralControl;
li.Text += " </tr> ";
}
//没有考虑到最后一行的补齐 ,自己加完了,好运

}
}