repeater 分列显示以及布局的实例代码

前台

复制代码 代码如下:


       
           
               
                   
                       

                   
               
           
       

                           
                               
                                   
                               
                               
                                   
                               
                               
                                   
                                   
                               
                               
                                   
                               
                           

                                       
                                   

                                       
                                   

                                       
                                   

                                       
                                        <%--    --%>
                                       
                                       
                                        <%----%>
                                   

                                       
                                   

                       

   


后台

复制代码 代码如下:

  public   int i = 1;               

protected void Page_Load(object sender, EventArgs e)

        {

            string sqlstr = @"data source=PC-LENOVE\SQLEXPRESS;initial catalog=KFC;USER ID=SA;PASSWORD=abing520";

            SqlConnection con = new SqlConnection(sqlstr);

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "SELECT * FROM Foods";

            cmd.Connection = con;

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();

            adapter.Fill(dt);

            cmd.Dispose();

            con.Dispose();

            this.Repeater1.DataSource = dt;

            this.Repeater1.DataBind();

        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)

        {

            if (i % 4 == 0)//4是一行显示列数

            {

                e.Item.Controls.Add(new LiteralControl(""));

            }

            i++;

        }


你可能感兴趣的:(repeater 分列显示以及布局的实例代码)