一、下面的代码实现,每行显示三列
前台代码:
<table>
<tr>
<asp:repeater id="repeater1" runat="server">
<itemtemplate>
<td><%#databinder.eval(container.dataitem,"thing")%></td>
</itemtemplate>
</asp:repeater>
</tr>
</table>
后台代码:
protected int i=1;
private void page_load(object sender, system.eventargs e)
{
xmlserializer ser = new xmlserializer(typeof(dataset));
dataset ds = new dataset("mydataset");
datatable t = new datatable("table1");
datacolumn c = new datacolumn("thing");
t.columns.add(c);
ds.tables.add(t);
datarow r;
for(int i = 0; i<10;i++)
{
r = t.newrow();
r[0] = i;
t.rows.add(r);
}
this.repeater1 .datasource =ds.tables [0].defaultview ;
this.repeater1.databind ();
}
private void repeater1_itemdatabound(object sender, system.web.ui.webcontrols.repeateritemeventargs e)
{
if(i%3==0&&i>0)
{
e.item.controls.add(new literalcontrol("</tr><tr>"));
}
i++;
}
新闻热点
疑难解答
图片精选