当前位置:首页  »  编程知识  »  Repeater 三层嵌套(真正能嵌套的代码)

  • Repeater 三层嵌套(真正能嵌套的代码)

  • 网络教育吧,鉴于大家对编程知识十分关注,我们编辑小组在此为大家搜集整理了“Repeater 三层嵌套(真正能嵌套的代码)”一文,供大家参考学习!

    ASPX:


             
             
             

    •            
      <%#Eval("x_classname") %>

                 
                 
                 

                   

                 
                 

    •                
      <%#Eval("x_classname") %>

                         
                     
                     

                       

                         
                         

    •                    
      <%#Eval("x_classname") %>

                         

    •                    

                     

                     
                     
                     
                 
                 
                 
                 
             
             

    CS:
     protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["login"] == null)
            {
                Response.Redirect("login.aspx");
                Response.End();
            }

            OleDbConnection conn = dbopen.getDB();

            string bStr = "select id,x_classname,taxis,preid from Table where preid=0 order by taxis asc,id asc";
            OleDbDataAdapter rs = new OleDbDataAdapter(bStr,conn);
            conn.Open();
            DataSet rd = new DataSet();
            rs.Fill(rd);
            bClass.DataSource = rd;
            bClass.DataBind();
            conn.Close();
        }

        protected void bClassList(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 bsClass = (Repeater)e.Item.FindControl("bsClass");//找到要绑定数据的Repeater
                if (bsClass != null)
                {
                    OleDbConnection sc = dbopen.getDB();
                    string ssql = "select id,x_classname,taxis,preid from Table where preid="+preid+" order by taxis asc,id asc";
                   
                    OleDbDataAdapter srs = new OleDbDataAdapter(ssql,sc);
                    sc.Open();
                    DataSet srd = new DataSet();
                    srs.Fill(srd);

                    bsClass.DataSource = srd;
                    bsClass.DataBind();
                    sc.Close();
                }
            }
        }
        protected void bsClassList(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 sClass = (Repeater)e.Item.FindControl("sClass");//找到要绑定数据的Repeater
                if (sClass != null)
                {
                    OleDbConnection sc = dbopen.getDB();
                    string ssql = "select id,x_classname,taxis,preid from Table where preid=" + preid + " order by taxis asc,id asc";

                    OleDbDataAdapter srs = new OleDbDataAdapter(ssql, sc);
                    sc.Open();
                    DataSet srd = new DataSet();
                    srs.Fill(srd);

                    sClass.DataSource = srd;
                    sClass.DataBind();
                    sc.Close();
                }

            }
        }


    以上为相同色彩对应
    这里要特别提醒的是,在用多层嵌套时,一定要用DATASET绑定,要不然无法使用.

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