大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
asp.net在Repeater嵌套的Repeater中使用复选框
来自森大科技官方博客 http://www.cnsendblog.com/index.php/?p=109
.aspx文件中:
<%–顶层Repeater–%>
<asp:Repeater ID=“rptChannel” runat=“server”>
<%# Eval(“ChannelName”)%>
<%–嵌套的Repeater,指定使用后台创建的Releation来获取数据源–%>
<asp:Repeater ID=“rptClassify” DataSource=’<%# Eval(“myrelation”) %>’ runat=“server”>
<asp:Label ID=“lbl_FlagName” runat=“server” Text=’<%# Eval(“FlagName”)%>’></asp:Label>
</asp:Repeater >
<%–end 嵌套的Repeater,指定使用后台创建的Releation来获取数据源–%>
</asp:Repeater >
<%–end 顶层Repeater–%>
.aspx.cs文件中:
#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
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/182501.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...