Repeater嵌套Repeater并取得嵌套Repeater里面的…
2018-06-22 06:51:10来源:未知 阅读 ()
前台代码:
<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 + ",";
}
}
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:C#中堆和栈的区别分析
- 详解ASP.NET数据绑定操作中Repeater控件的用法 2020-01-18
- .NET中取得代码行数的方法 2019-12-30
- 如何取得Repeater控件选择的项目及注意事项 2019-10-08
- 实现Repeater控件的记录单选(二) 2018-06-22
- 实现Repeater控件的记录单选 2018-06-22
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
