62,046
社区成员
发帖
与我相关
我的任务
分享
<table cellspacing="0" border="0" style="width:106px;border-collapse:collapse;">
<tr><asp:Repeater ID="rptSections" runat="server" onitemdatabound="rptSections_ItemDataBound">
<ItemTemplate>
<td><div style="width:60px; margin-left:2px;">
<a href="#" style="text-decoration: none; color: #676767;"
runat="server" id="sectionLnk"></a>
</div></td>
<asp:Literal ID="ltrlBr" runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater></tr>
</table>
protected int tdIndex = 1;
protected void rptSections_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// 动态获取相栏目信息
RepeaterItem rptItem = e.Item;
DataRow dtRow = (rptItem.DataItem as DataRowView).Row;
int id = dtRow.Field<int>("ID");
string sectionName = dtRow.Field<string>("Name");
// 动态设置相关栏目超链接
HtmlAnchor sectionLnk = rptItem.FindControl("sectionLnk") as HtmlAnchor;
sectionLnk.Title = sectionName;
sectionLnk.HRef = "SectionPage.aspx?id=" + id + "&cityid=" + GetCityId();
sectionLnk.InnerText = sectionName;
// repeater嵌套使用,内层repeater每次初始置1后操作
if (rptItem.ItemIndex == 0)
{
tdIndex = 1;
}
if (tdIndex % 3 == 0)
{
Literal ltrlBr = rptItem.FindControl("ltrlBr") as Literal;
ltrlBr.Text = "</tr><tr>";
}
tdIndex++;
}
<table cellspacing="0" border="0" style="width:106px;border-collapse:collapse;">
<tr><asp:Repeater ID="rptSections" runat="server" onitemdatabound="rptSections_ItemDataBound">
<ItemTemplate>
<td><div style="width:60px; margin-left:2px;">
<a href="#" style="text-decoration: none; color: #676767;"
runat="server" id="sectionLnk"></a>
</div></td>
</ItemTemplate>
</asp:Repeater></tr>
</table>
protected int tdIndex = 1;
protected void rptSections_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// 动态获取相栏目信息
DataRow dtRow = (e.Item.DataItem as DataRowView).Row;
int id = dtRow.Field<int>("ID");
string sectionName = dtRow.Field<string>("Name");
// 动态设置相关栏目超链接
HtmlAnchor sectionLnk = e.Item.FindControl("sectionLnk") as HtmlAnchor;
sectionLnk.Title = sectionName;
sectionLnk.HRef = "SectionPage.aspx?id=" + id + "&cityid=" + GetCityId();
sectionLnk.InnerText = sectionName;
// repeater嵌套使用,内层repeater每次初始置1后操作
if (e.Item.ItemIndex == 0)
{
tdIndex = 1;
}
if (tdIndex % 3 == 0)
{
Literal ltrlBr = new Literal();
ltrlBr.Text = "</tr><tr>";
e.Item.Controls.Add(ltrlBr);
}
tdIndex++;
}