asp.net在Repeater嵌套的Repeater中使用復選框詳解
更新時間:2018年12月01日 20:20:13 作者:森大科技
這篇文章主要介紹了asp.net在Repeater嵌套的Repeater中使用復選框,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
.aspx文件中:
<%--頂層Repeater--%> <asp:Repeater ID="rptChannel" runat="server"> <itemtemplate> <br /><b><%# Eval("ChannelName")%></b> <%--嵌套的Repeater,指定使用后臺創(chuàng)建的Releation來獲取數(shù)據(jù)源--%> <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,指定使用后臺創(chuàng)建的Releation來獲取數(shù)據(jù)源--%> </itemtemplate> </asp:Repeater > <%--end 頂層Repeater--%>
.aspx.cs文件中:
#region Repeater嵌套的Repeater中使用復選框 //★Repeater嵌套-經(jīng)典運用★ 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 //……略相關數(shù)據(jù)庫操作代碼 #region 設置Repeater嵌套的Repeater中相應的復選框為選中狀態(tài) 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中使用復選框,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
Asp.Net模擬表單提交數(shù)據(jù)和上傳文件的實現(xiàn)代碼
這篇文章主要介紹了Asp.Net模擬表單提交數(shù)據(jù)和上傳文件的實現(xiàn)代碼,本文對3種情況都做了介紹,只有普通數(shù)據(jù)的表單、只上傳文件的表單、包含普通數(shù)據(jù)和上傳文件表單,需要的朋友可以參考下2014-08-08使用 Salt + Hash 將密碼加密后再存儲進數(shù)據(jù)庫
如果你需要保存密碼(比如網(wǎng)站用戶的密碼),你要考慮如何保護這些密碼數(shù)據(jù),象下面那樣直接將密碼寫入數(shù)據(jù)庫中是極不安全的,因為任何可以打開數(shù)據(jù)庫的人,都將可以直接看到這些密碼2012-12-12使用?HttpReports?監(jiān)控?.NET?Core?應用程序的方法
這篇文章主要介紹了使用?HttpReports?監(jiān)控?.NET?Core?應用程序的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03