注册 登录
编程论坛 ASP.NET技术论坛

repeater嵌套数据绑定问题.急!

lifongmaples 发布于 2011-03-19 01:35, 922 次点击
请教高手:
    本人现需要使用repeater控件实现一个嵌套数据显示。实现如下界面功能。
       食品类:
             大米、猪肉、牛肉
       交通工具:
             小轿车、公交车、电动车
       日用品:
              纸巾、洗发水、洗衣粉

      本人愚钝,请尽量将代码详细一点,谢谢!
3 回复
#2
SULUM2011-03-20 20:15

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //查询出父级的名称放到dataTable
               // 绑定到repeate里去
                repeater1.DataSource ="";               
                repeater1.DataBind();

        }

//这个是嵌套的第二个repeater
protected void rt_Title_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = e.Item.DataItem as DataRowView;
                if (null != row)
                {
                    string ForID = row["应用的父级ID"].ToString();
                    Repeater rp_Title = e.Item.FindControl("名称") as Repeater;
                  
                    if (null !=rp_Title)
                    {
                        //得到的dataTable绑定
                        rp_Title.DataSource = “”;
                        rp_Title.DataBind();
                       
                    }
                }
            }
        }

这样就可以实现你的想要的功能了。
#3
lifongmaples2011-03-21 11:38
回复 2楼 SULUM
谢谢.我已经找到了一个较为简洁的方法了.
#4
jiasenlin2011-04-21 16:24
回复 3楼 lifongmaples

什么方法。写出来。我也用一下。
1