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 ...
随机推荐
- .NET LINQ 聚合操作
聚合操作 聚合运算从值集合计算单个值. 从一个月的日温度值计算日平均温度就是聚合运算的一个示例. 方法 方法名 说明 C# 查询表达式语法 Visual Basic 查询表达式语法 更多信息 ...
- seajs hello world
http://localhost/seajs/index.html <!doctype html> <head> <title>Hello Seajs</ti ...
- iOS之九宫格图片
照片 现在人们的生活越来越丰富了,很多美好的瞬间都定格在一张张色彩绚丽的照片上,或许把照片珍藏在相册里,或许通过社交软件分享给亲朋好友.那社交软件上的照片是以什么形式展现的呢?那么接下来就要说到九宫格 ...
- PHP字符串函数
php字符串处理函数大全 addcslashes — 为字符串里面的部分字符添加反斜线转义字符addslashes — 用指定的方式对字符串里面的字符进行转义bin2hex — 将二进制数据转换成十六 ...
- _stdcall,_cdecl区别
(1) _stdcall调用 _stdcall是Pascal程序的缺省调用方式,参数采用从右到左的压栈方式,被调函数自身在返回前清空堆栈. WIN32 Api都采用_stdcall调用方式,这样的宏定 ...
- UWP 下拉刷新控件(PullToRefreshControl)
最近项目里面有下拉刷新的需求,自己做了一个,效果还不错. <Style TargetType="local:PullToRefreshControl"> <Set ...
- java.lang.OutOfMemoryError: bitmap size exceeds VM budget解决方法
1 BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时,有时会遇到该错误.这往往是由于图片过大造成的.要想正常使用,则需要分配更少的内 ...
- UITableView在设置contentOffset的同时也reload,造成tableView的contentOffset偏差
最近在写一个聊天的框架,遇到一个奇葩的问题,就是发送聊天记录的时候(需要tableView上移,显示出最新的记录),增加一条记录无疑需要reload一下(大家都明白的),这是就会出现头疼的问题,页面显 ...
- supervisor:How is this different from daemontools ?
"daemontools has too much focus on security as opposed to being a process manager for my taste. ...
- 作弊Q-百威
===_=374793763===_= 2652880032 865580818 大康 2652880032 春牛 3479301404 皮卡丘 3242026908 舍得放手