前台代码:

   <asp:Repeater ID="RepeaterScene" runat="server" OnItemDataBound="RepeaterList_ItemDataBound">
                  <ItemTemplate>
                    <tr>
                        <td class="bg_1" style="text-align: right; width: 75px; height: 36px;">
                            <%#Eval("ClassName") %>:
                        </td>
                        <asp:HiddenField ID="hideClassId" runat="server" Value='<%#Eval("ClassId") %>' />
                        <asp:Repeater ID="RepeaterClassScene" runat="server">
                        <ItemTemplate>
                        <td>
                            <asp:CheckBoxList ID="CheckBoxList1"  runat="server" RepeatDirection="Horizontal">
                            </asp:CheckBoxList>
                        </td>
                           </ItemTemplate>
                       </asp:Repeater>
                    </tr>
                    </ItemTemplate>
                   </asp:Repeater>

你要弄清楚,当绑定Repeater的数据源中没有值时,上面这些东西不显示在界面中,这样就可以做到添加数据后在前台动态显示。
有数据时,显示效果

后台代码:
  //显示所有景色类型

        private void BindScene()
        {     
            DataTable scene = new NJL.Bll.SceneTypeClass().GetScene(" where ParentId=0 and isshow=1");
            RepeaterScene.DataSource = scene;
            RepeaterScene.DataBind();
        }
// Repeater 的ItemDataBound 方法    
        protected void RepeaterList_ItemDataBound(object sender,RepeaterItemEventArgs e)
        { 
            if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
            {
                HiddenField hideClassId = (HiddenField)e.Item.FindControl("hideClassId");
              
                if(!string.IsNullOrEmpty(hideClassId.Value))
                {
                    Repeater relist = (Repeater)e.Item.FindControl("RepeaterClassScene");
    
                    string where =string.Format(" where isshow=1 and ParentId='{0}'",hideClassId.Value);
                    DataTable cla = new NJL.Bll.SceneTypeClass().GetScene(where);
                    relist.DataSource = cla;
                     relist.DataBind();
                  
                     CheckBoxList ck = (CheckBoxList)relist.Items[0].FindControl("CheckBoxList1");
                     ck.DataValueField = "ClassId";
                     ck.DataTextField = "ClassName";
                     ck.DataSource = cla;
                     ck.DataBind();                 
                }
            }
        }
//获取设置选中的类型  获取Repeater内嵌的控件CheckBoxList 需要遍历                
                    if(!string.IsNullOrEmpty(m.SceneType))
                    {
                        string[] follow = m.SceneType.Split(',');
                        for (int i = 0; i < RepeaterScene.Items.Count;i++ )
                        {
                            Repeater rep2 = (Repeater)RepeaterScene.Items[i].FindControl("RepeaterClassScene");
                            for (int j = 0; j < rep2.Items.Count;j++ )
                            {
                                CheckBoxList cbx = (CheckBoxList)rep2.Items[j].FindControl("CheckBoxList1");
                                foreach(ListItem item in cbx.Items)
                                {
                                    foreach(string s in follow)
                                    {
                                        if(item.Value==s)
                                        {
                                            item.Selected = true;
                                        }
                                    }
                                }
                            }
                        }
                    } //保存选中的景点类型
    //旅游景点类型
                string scenlist="";
                for (int s = 0; s < RepeaterScene.Items.Count;s++ )
                {
                    Repeater rep2 = (Repeater)RepeaterScene.Items[s].FindControl("RepeaterClassScene");
                    for (int x = 0; x < rep2.Items.Count;x++ )
                    {
                        CheckBoxList cbx = (CheckBoxList)rep2.Items[x].FindControl("CheckBoxList1");
                        foreach(ListItem item in cbx.Items)
                        {
                            if(item.Selected==true)
                            {
                                scenlist += item.Value + ",";
                            }
                        }
                    }
                }
 

Repeater嵌套Repeater并取得嵌套Repeater里面的控件的更多相关文章

  1. (ScrollViewer或者有滚动条的控件)嵌套一个(ScrollViewer或者有滚动条的控件)禁用里面的滚动条

    转自:http://blog.csdn.net/haylhf/article/details/8351203 后有改动 在C# 中,两个ScrollViewer嵌套在一起或者ScrollViewer里 ...

  2. FineUIMvc随笔 - 怎样在控件中嵌套 HTML

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户需求 有网友在<FineUI总群1>问这么一个问题:怎么把 HTML 嵌套在控件中? 这是很多刚学习 FineU ...

  3. FineUIMvc随笔(2)怎样在控件中嵌套 HTML

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户需求 有网友在<FineUI总群1>问这么一个问题:怎么把 HTML 嵌套在控件中? 这是很多刚学习 FineU ...

  4. Repeater 控件的嵌套使用

      Repeater 控件的嵌套使用   ItemDataBound:数据绑定的时候(正在进行时)发生,多用在Repeater控件嵌套,对子Repeater控件进行数据绑定及模板列中统计列的计算处理等 ...

  5. ASP.NET- 查找Repeater控件中嵌套的控件

    如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...

  6. 使用Repeater控件实现三层嵌套以及分页效果

    PS: 第一次用Repeater控件 记录一下 请忽略我的命名不规范  请忽略我的最终效果图(太丑了) 需要用到的朋友可以自行调整的漂亮点 ====================最终效果图===== ...

  7. Repeater控件 ---表格展示数据

    简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...

  8. Reapter控件的特殊使用:使用EVAL调取asp:Repeater里面绑定的值来进行判断 根据从数据库获取的数据进行判断 ,进而显示成想要的内容

    1.这个判断的过程你可以写在后台,如先在后台写一个public类型的方法:public bool CheckAduit(string code){ //根据你传入的code来判断,并返回true或者f ...

  9. asp控件Repeater运用

    双层repeater嵌套 <asp:Repeater ID="rpt_dataRepeatgroup" runat="server" OnItemData ...

随机推荐

  1. 【目录】linux

    linux 学习1 学习2 学习3 学习4 学习5 学习6 学习7 jdk安装 配置SSH免密码登陆 linux下运行java程序

  2. qt creator 源代码中含有中文编译报错

    Tools-Options-Text Editor-Behavior-File Encoding-Default encoding:UTF-8 Tools-Options-Text Editor-Be ...

  3. 踩个猴尾不容易啊 Canvas画个猴子

    踩个猴尾不容易啊  Canvas画个猴子 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...

  4. thinkphp中volist标签

    volist标签 volist标签主要用于在模板中循环输出数据集或者多维数组 volist(name,id,offset,length,key,mod,empty) name(必须):要输出的数据模型 ...

  5. python:列表与元组

    1.python包含六种内建的序列,列表和元组是其中的两种,列表可以修改,元组则不能 2.通用序列操作 2.1 索引:和C#的区别是索引可以为负数,最后一个元素索引为-1,索引超出范围会报错 例:&g ...

  6. NetApp 监控

    http://support.ipmonitor.com/mibs/network-appliance-mib/tree.aspx http://www.360doc.com/content/10/1 ...

  7. (一)安卓小app开发之基础环境搭建

    一.准备工作: 1.下载Android Studio开发环境 https://dl.google.com/dl/android/studio/ide-zips/2.1.1.0/android-stud ...

  8. 前端设计中关于外部js文件加载的速度优化

    在一般情况下,许多人都是将<script>写在了<head>标签中,而许多浏览器都是使用单一的线程来加载js文件的,从上往下,从左往右. 若是加载过程出错,那么网页就会阻塞,就 ...

  9. Winform实现用多线程、百度地图API解析某公司的物理地址

    前言 作为一个很挫的C#新手总喜欢自己写点儿不着边际的东西,本人是个新手加菜鸟,写B/S的,工作中,任务完成了,空闲下来,总想继续学点儿什么,由此触发了本篇文章了.个人一直认为,.NET中,C/S所要 ...

  10. 注解@RequestMapping 的使用

    1首先@RequestMapping 中的值,我们说请求方法l路径,请求url我们都知道怎么请求了,在第一节helloworld中, 我们先说我们先建一个类,RequestMappingTest 方法 ...