当前位置:首页  »  编程知识  »  Repeater 嵌套

  • Repeater 嵌套

  • 网络教育吧编程知识编辑为广大网友搜集整理了:Repeater 嵌套绩等信息,祝愿广大网友取得需要的信息,参考学习。

    我们在写程序时还有双循环呢,那么在Repeater 里也需要嵌套一个嵌套Repeater,Repeater 嵌套方法:

    ASPX内容

    Repeater ID="topBtn" runat="server" OnItemDataBound="bClassOnitemdataBound">
           

  • '',''1'')">
            ">&nbsp;&nbsp;<%#Eval("classname") %>
      " style="display:none;">
                  Repeater ID="topBtnS" runat="server">
                     
    • "><%#Eval("classname") %>

    •            
             

  •        
       

    CS文件内容:

    protected void Page_Load(object sender, EventArgs e)
        {
            string kyd = Request["keyword"];
            //if(kyd!=null){keyword.Text=kyd.ToString();}

            SqlConnection conn = dbopen.getconnection();

            string btnStr = "select * from table where preid=0 order by taxis asc,id desc";
            //Sqlmand btnRs = new Sqlmand(btnStr,conn);
            SqlDataAdapter btnRs = new SqlDataAdapter(btnStr,conn);
            DataSet btnRd = new DataSet();
            btnRs.Fill(btnRd);
            topBtn.DataSource = btnRd;
            topBtn.DataBind();
            conn.Close();
    }


        protected void bClassOnitemdataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            
            {
                string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString();//获得对应ID
                Repeater topBtnS = (Repeater)e.Item.FindControl("topBtnS");
                if (topBtnS != null)
                {
                    SqlConnection sc = dbopen.getconnection();
                    string ssql = "select * from table where preid=" + preid + " order by taxis asc,id desc ";
                    sc.Open();
                    Sqlmand srs = new Sqlmand(ssql, sc);
                    topBtnS.DataSource = srs.ExecuteReader();
                    topBtnS.DataBind();
                    sc.Close();
                }

            }
        }

    注意看不能色彩对应部分一定要对应上,要不然就会出错,这样就实现了Repeater 嵌套显示信息了。

     

    全国精品课程资源库
  • 友情链接