想问下repeater多列显示问题
外面加个
int tdIndex = 1;
绑定事件里用
if (tdIndex % 3 == 0)
{
Literal ltrlBr = new Literal();
ltrlBr.Text = "</tr><tr>";
e.Item.Controls.Add(ltrlBr);
}
tdIndex++;
确实可以多列显示,但页面回发后就全部单行显示了,能解决吗?
DataList可以,但感觉只用来显示数据太过浪费,耗时长
外面加个
int tdIndex = 1;
绑定事件里用
if (tdIndex % 3 == 0)
{
Literal ltrlBr = new Literal();
ltrlBr.Text = "</tr><tr>";
e.Item.Controls.Add(ltrlBr);
}
tdIndex++;
确实可以多列显示,但页面回发后就全部单行显示了,能解决吗?
DataList可以,但感觉只用来显示数据太过浪费,耗时长
解决方案 »
- 关于 lucene 实现 adj 查询的方法
- 类似csdn头像弹出框问题?
- 200分向csdn的牛人们问个关于TabScript 的问题(有点难)解决再开贴
- 关于Visual Studio 2003创建Web项目的问题。
- 关于使用javascript在客户端对输入进行验证的问题
- 在线等!急,数据库还原问题!!
- 我用js脚本只能实现静态的树,如何实现从数据库读取数据后动态生成树?
- 如何过滤脚本代码?
- ASP.NET如何统计网站访问量,同一IP在网页有效期内计数一次,求代码
- 无法从web服务器获得项目文件
- 请阅读以下MSDN短文,然后回答问题,每小题10分,呵呵
- 我写了一个类,里面要输出HTML控件,但是在类里面获取不到HTML控件
<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++;
}
初始加载确实可行,回发后变成单行显示了,咋整?
有人说用AlternatingItemTemplate显示2列,确实可以,我就想知道要是超过2列呢?只能用DataList吗?
会不会太浪费啊?
那样的话,要重新获取数据源,重新绑定外层Repeater数据
是不是比起DataList就麻烦了?我就想优化一下,不知在显示时哪个更节约时间(多列)
如果改DIV,基本就是顶端对齐了
1.直接把Literal加到了前台,不设置文本值。
2.后台动态获取Literal控件,当被操作项该换行时,设置其文本值为"</tr><tr>"。
3.打完收工。嘘。前台:<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++;
}