前台代码Code:
<table>
<asp:Repeater runat="server" ID="rep" OnItemDataBound="rep_ItemDataBound">
<ItemTemplate>
<tr id="row" runat="server">
<td>
<%# Eval("title") %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<br />
/* UI */
<ul>
<asp:Repeater runat="server" ID="rep1" OnItemDataBound="rep_ItemDataBound1">
<ItemTemplate>
<li runat="server" id="row1">
<%# Eval("title") %></li>
</ItemTemplate>
</asp:Repeater>
</ul>
<asp:Repeater runat="server" ID="rep" OnItemDataBound="rep_ItemDataBound">
<ItemTemplate>
<tr id="row" runat="server">
<td>
<%# Eval("title") %>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<br />
/* UI */
<ul>
<asp:Repeater runat="server" ID="rep1" OnItemDataBound="rep_ItemDataBound1">
<ItemTemplate>
<li runat="server" id="row1">
<%# Eval("title") %></li>
</ItemTemplate>
</asp:Repeater>
</ul>
后台代码Code:
// 当数据绑定格式为Table时,将类型转行成 HtmlTableRow
protectedvoid rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((e.Item.ItemIndex +1) ==1|| (e.Item.ItemIndex +1) ==2|| (e.Item.ItemIndex +1) ==3)
{
((HtmlTableRow)e.Item.FindControl("row")).Attributes.Add("style", "color:red");
}
}
}
// 当数据绑定格式为UI时,将类型转行成 HtmlGenericControl
protectedvoid rep_ItemDataBound1(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((e.Item.ItemIndex +1) ==1|| (e.Item.ItemIndex +1) ==2|| (e.Item.ItemIndex +1) ==3)
{
((HtmlGenericControl)e.Item.FindControl("row1")).Attributes.Add("style", "color:red");
}
}
}
protectedvoid rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((e.Item.ItemIndex +1) ==1|| (e.Item.ItemIndex +1) ==2|| (e.Item.ItemIndex +1) ==3)
{
((HtmlTableRow)e.Item.FindControl("row")).Attributes.Add("style", "color:red");
}
}
}
// 当数据绑定格式为UI时,将类型转行成 HtmlGenericControl
protectedvoid rep_ItemDataBound1(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((e.Item.ItemIndex +1) ==1|| (e.Item.ItemIndex +1) ==2|| (e.Item.ItemIndex +1) ==3)
{
((HtmlGenericControl)e.Item.FindControl("row1")).Attributes.Add("style", "color:red");
}
}
}