ASP.NET技巧:repeater实现多列显示_.net资料_编程技术-你的首页-uuhomepage.com
一、下面的代码实现,每行显示三列
前台代码:
<%#DataBinder.Eval(Container.DataItem,"thing")%>
后台代码:
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("
"));
}
i++;
}