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的数据源中没有值时,上面这些东西不显示在界面中,这样就可以做到添加数据后在前台动态显示。
有数据时,显示效果
后台代码:
//显示所有景色类型 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 ...
随机推荐
- String字符串去掉最后一个","号的几种方式
String a = "struts-default.xml,struts-plugin.xml,struts.xml"; String[] bStrings = a.split( ...
- Qt文件路径分隔符
QDir::toNativeSeparators()QDir::separator()
- Java Mysql连接池配置和案例分析--超时异常和处理
前言: 最近在开发服务的时候, 发现服务只要一段时间不用, 下次首次访问总是失败. 该问题影响虽不大, 但终究影响用户体验. 观察日志后发现, mysql连接因长时间空闲而被关闭, 使用时没有死链检测 ...
- 【leetcode】Search Insert Position
题目描述: Given a sorted array and a target value, return the index if the target is found. If not, retu ...
- 在Salesforce中向外公布Service去创建Lead,并且用Asp.Net去调用此Service
1):在Salesforce中如何配置,向外公布此Service,请看如下链接: http://www.shellblack.com/marketing/web-to-lead/ 2):如何在Asp. ...
- JupyterNotebook如何添加table of content
不要总是等待,而是去创造 方法一 ipython notebook升级成了jupyter notebook,在4.x之后的版本,jupyter提供了jupyter-nbextension命令来安装和启 ...
- 如何判断css是否加载完成
要判断这个 CSS 文件是否加载完毕,各个浏览器的做法差异比较大,这次要说IE浏览器做的不错,我们可以直接通过onload方法来处理CSS加载完成以后的处理: // 代码节选至seajs functi ...
- cas单点登录时报Invalid credentials
CAS4后默认的密码验证不是简单的相同了.在配置文件deployerConfigContext.xml里可以找到, 默认是 Username:casuser Password:Mellon
- offset图
- Leetcode Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...