前台代码:

   <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. PHP文件可限速下载代码

    <?php include("DBDA.class.php"); $db = new DBDA(); $bs = $_SERVER["QUERY_STRING&qu ...

  2. 表格中每行的checkbox只能选中其中一个jquery实现

    HTML代码: <span class="number">12.</span> <div class="survey_txt mgl20&q ...

  3. 单词(bzoj 3172)

    Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input 第一个一个整数N,表示有多少个单词,接下来N ...

  4. SQL IN ANY ,(all any) 区别

    EXITS 和 IN 的区别: 从效率来看: 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; T1数据量小而T ...

  5. MySQL存储引擎之Myisam和Innodb总结性梳理

    Mysql有两种存储引擎:InnoDB与Myisam,下表是两种引擎的简单对比   MyISAM InnoDB 构成上的区别: 每个MyISAM在磁盘上存储成三个文件.第一个 文件的名字以表的名字开始 ...

  6. come on,逆战

    腾讯游戏       琳琅天上        逆战                                                                            ...

  7. input上传按钮美化

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. Logistic回归 python实现

    Logistic回归 算法优缺点: 1.计算代价不高,易于理解和实现2.容易欠拟合,分类精度可能不高3.适用数据类型:数值型和标称型 算法思想: 其实就我的理解来说,logistic回归实际上就是加了 ...

  9. 为什么在soui中加载JPG文件失败

    在SOUI中解决解码器是一个独立的模块.不同的解码器决定了程序中能够加载什么样的图片类型.使用SComMgr来加载SOUI的模块时,debug模式下默认的图片解码器是imgdecoder-png.这个 ...

  10. requirejs(一)

    RequireJs已经流行很久了,我们在项目中也打算使用它.它提供了以下功能: 声明不同js文件之间的依赖 可以按需.并行.延时载入js库 可以让我们的代码以模块化的方式组织 初看起来并不复杂. 在h ...