.aspx文件中:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<%--顶层Repeater--%>
<asp:Repeater ID= "rptChannel" runat= "server" >
<itemtemplate>
<br /><b><%# Eval( "ChannelName" )%></b>
<%--嵌套的Repeater,指定使用后台创建的Releation来获取数据源--%>
<asp:Repeater ID= "rptClassify" DataSource= '<%# Eval("myrelation") %>' runat= "server" >
<itemtemplate>
<input type= "checkbox" id= "chk_FlagID" value= '<%# Eval("FlagID")%>' runat= "server" />
<asp:Label ID= "lbl_FlagName" runat= "server" Text= '<%# Eval("FlagName")%>' ></asp:Label>
</itemtemplate>
</asp:Repeater >
<%--end 嵌套的Repeater,指定使用后台创建的Releation来获取数据源--%>
</itemtemplate>
</asp:Repeater >
<%--end 顶层Repeater--%>
|
.aspx.cs文件中:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#region Repeater嵌套的Repeater中使用复选框
//Repeater嵌套-经典运用
string sqlstr1, sqlstr2;
sqlstr1 = "select distinct a.ChannelID,b.ChannelName from IE_FlagGroup a left join IE_Channel b on a.ChannelID=b.ChannelID where a.isClose=0 order by a.ChannelID asc" ;
sqlstr2 = "select * from IE_FlagGroup where isClose=0 order by FlagID asc" ;
DataSet dsChannel = DBFun.dataSetTwo(sqlstr1, "Channel" , sqlstr2, "Classify" , "myrelation" );
dsChannel.Relations.Add( "myrelation" , dsChannel.Tables[ "Channel" ].Columns[ "ChannelID" ], dsChannel.Tables[ "Classify" ].Columns[ "ChannelID" ], false );
this .rptChannel.DataSource = dsChannel.Tables[ "Channel" ]; //绑定顶层Repeater(注意:只要绑定顶层就好,嵌套层不能绑定)
this .rptChannel.DataBind();
#endregion
//……略相关数据库操作代码
#region 设置Repeater嵌套的Repeater中相应的复选框为选中状态
string [] selTeamflag = drw[ "Teamflag" ].ToString().Split( ',' );
HtmlInputCheckBox checkBox;
Repeater rpClass;
for ( int i = 0; i < this .rptChannel.Items.Count; i++)
{
rpClass = (Repeater) this .rptChannel.Items[i].FindControl( "rptClassify" );
for ( int j = 0; j < rpClass.Items.Count; j++)
{
checkBox = (HtmlInputCheckBox)rpClass.Items[j].FindControl( "chk_FlagID" );
if (selTeamflag.Contains(checkBox.Value))
checkBox.Checked = true ;
}
}
#endregion
#region 获取Repeater嵌套的Repeater中的复选框所选择的值的组合,以","隔开
string str_Teamflag = "" ;
HtmlInputCheckBox checkBox;
Repeater rpClass;
for ( int i = 0; i < this .rptChannel.Items.Count; i++)
{
rpClass = (Repeater) this .rptChannel.Items[i].FindControl( "rptClassify" );
for ( int j = 0; j < rpClass.Items.Count; j++)
{
checkBox = (HtmlInputCheckBox)rpClass.Items[j].FindControl( "chk_FlagID" );
if (checkBox.Checked)
str_Teamflag += checkBox.Value + "," ;
}
}
if (str_Teamflag != "" )
{
//去除最后一个字符
//str_Teamflag = str_Teamflag.Substring(0, str_Teamflag.Length - 1);
str_Teamflag = str_Teamflag.Remove(str_Teamflag.Length - 1);
}
#endregion
|
以上所述是小编给大家介绍的asp.net在Repeater嵌套的Repeater中使用复选框,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:http://www.cnsendblog.com/index.php/?p=109
相关文章
猜你喜欢
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 52
-
2025-05-29 65
-
2025-05-29 26
-
2025-05-29 30
-
2025-05-29 108
热门评论