Repeater嵌套Repeater并取得嵌套Repeater里面的控件
前台代码:
<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的数据源中没有值时,上面这些东西不显示在界面中,这样就可以做到添加数据后在前台动态显示。
有数据时,显示效果


9SH`BOXO6N.png)
后台代码:
//显示所有景色类型 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里面的控件的更多相关文章
- (ScrollViewer或者有滚动条的控件)嵌套一个(ScrollViewer或者有滚动条的控件)禁用里面的滚动条
转自:http://blog.csdn.net/haylhf/article/details/8351203 后有改动 在C# 中,两个ScrollViewer嵌套在一起或者ScrollViewer里 ...
- FineUIMvc随笔 - 怎样在控件中嵌套 HTML
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户需求 有网友在<FineUI总群1>问这么一个问题:怎么把 HTML 嵌套在控件中? 这是很多刚学习 FineU ...
- FineUIMvc随笔(2)怎样在控件中嵌套 HTML
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户需求 有网友在<FineUI总群1>问这么一个问题:怎么把 HTML 嵌套在控件中? 这是很多刚学习 FineU ...
- Repeater 控件的嵌套使用
Repeater 控件的嵌套使用 ItemDataBound:数据绑定的时候(正在进行时)发生,多用在Repeater控件嵌套,对子Repeater控件进行数据绑定及模板列中统计列的计算处理等 ...
- ASP.NET- 查找Repeater控件中嵌套的控件
如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...
- 使用Repeater控件实现三层嵌套以及分页效果
PS: 第一次用Repeater控件 记录一下 请忽略我的命名不规范 请忽略我的最终效果图(太丑了) 需要用到的朋友可以自行调整的漂亮点 ====================最终效果图===== ...
- Repeater控件 ---表格展示数据
简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...
- Reapter控件的特殊使用:使用EVAL调取asp:Repeater里面绑定的值来进行判断 根据从数据库获取的数据进行判断 ,进而显示成想要的内容
1.这个判断的过程你可以写在后台,如先在后台写一个public类型的方法:public bool CheckAduit(string code){ //根据你传入的code来判断,并返回true或者f ...
- asp控件Repeater运用
双层repeater嵌套 <asp:Repeater ID="rpt_dataRepeatgroup" runat="server" OnItemData ...
随机推荐
- mint17.3挂载u盘出现错误:mount:unknown filesystem type 'exfat'
mint17.3挂载u盘出现错误:mount:unknown filesystem type 'exfat' 安装exfat-fuse: sudo apt-get install exfat-fuse
- Huffman树实现_详细注释
//最优二叉树 #include <iostream> #include <iomanip> using namespace std; //定义结点类型 //[weight | ...
- poj 3280 Cheapest Palindrome
链接:http://poj.org/problem?id=3280 思路:题目给出n种m个字符,每个字符都有对应的添加和删除的代价,求出构成最小回文串的代价 dp[i][j]代表区间i到区间j成为回文 ...
- iframe无刷新跨域并获得返回值
参考:http://geeksun.iteye.com/blog/1070607 /** * iframe跨域提交大数据 * @param action 跨域地址 * @param arr [ {na ...
- github之git基本命令介绍的简单整理
git 格式: git [--version] [--exec-path[=<path>]] [--html-path] [--info-path] [-p|--paginate|--no ...
- Guava学习笔记(3):复写的Object常用方法
转自:http://www.cnblogs.com/peida/p/Guava_Objects.html 在Java中Object类是所有类的父类,其中有几个需要override的方法比如equals ...
- 数据库错误:check the manual that corresponds to your MySQL server version for the right sy
检查对应到您的MySQL服务器版本附近使用正确的语法手册 数据库插入的时候出现上述问题,总结了两方面原因: 1.语法错误,这是百度之得到的大部分结果,但是没有解决我的问题 2.仔细观察我的sql语句, ...
- jquery 事件冒泡的介绍以及如何阻止事件冒泡
在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个事件会向这个对象的父级 ...
- 我的c++学习(12)指针作为函数参数
◆ 引用调用与指针传值调用C++中函数的参数的基本使用方法是传值.为了弥补单纯传值的不足,以引用作为函数的参数,从逻辑上讲引用是别名,在函数中对参数的操作,就是对实参的操作,而在物理上是传实参的地址. ...
- Create a REST API with Attribute Routing in ASP.NET Web API 2
原文:http://www.asp.net/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute- ...