這篇文章將為大家詳細(xì)講解有關(guān)使用asp.net怎么在Repeater中使用復(fù)選框,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
.aspx文件中:
<%--頂層Repeater--%> <asp:Repeater ID="rptChannel" runat="server"> <itemtemplate> <br /><b><%# Eval("ChannelName")%></b> <%--嵌套的Repeater,指定使用后臺(tái)創(chuàng)建的Releation來(lái)獲取數(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,指定使用后臺(tái)創(chuàng)建的Releation來(lái)獲取數(shù)據(jù)源--%> </itemtemplate> </asp:Repeater > <%--end 頂層Repeater--%>
.aspx.cs文件中:
#region Repeater嵌套的Repeater中使用復(fù)選框 //★Repeater嵌套-經(jīng)典運(yùn)用★ 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 //……略相關(guān)數(shù)據(jù)庫(kù)操作代碼 #region 設(shè)置Repeater嵌套的Repeater中相應(yīng)的復(fù)選框?yàn)檫x中狀態(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中的復(fù)選框所選擇的值的組合,以","隔開(kāi) 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 != "") { //去除最后一個(gè)字符 //str_Teamflag = str_Teamflag.Substring(0, str_Teamflag.Length - 1); str_Teamflag = str_Teamflag.Remove(str_Teamflag.Length - 1); } #endregion
關(guān)于使用asp.net怎么在Repeater中使用復(fù)選框就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享題目:使用asp.net怎么在Repeater中使用復(fù)選框-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://www.chinadenli.net/article0/ijeio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、云服務(wù)器、企業(yè)網(wǎng)站制作、企業(yè)建站、微信小程序、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容