WEB开发网
开发学院WEB开发ASP.NET repeater实现多列显示 阅读

repeater实现多列显示

 2006-10-25 17:17:08 来源:WEB开发网   
核心提示:一、下面的代码实现,每行显示三列前台代码:<table><tr><asp:repeater id="Repeater1" runat="server"><ItemTemplate><td><%#DataBinder

一、下面的代码实现,每行显示三列

前台代码:
<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++;
  }
http://www.cnblogs.com/bccu/archive/2006/10/24/538506.html

Tags:repeater 实现 多列

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接