日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

DataList分页,保存CheckBox控件状态

發(fā)布時(shí)間:2025/3/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DataList分页,保存CheckBox控件状态 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

1、DataList中嵌套CheckBox

<asp:DataList ID="dlNews" runat="server"> <HeaderTemplate><table cellpadding="0" cellspacing="0"><tr><td align="center">復(fù)選框</td></tr></table></HeaderTemplate><ItemTemplate><table cellpadding="0" cellspacing="0"><tr><td align="center"><asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" /></td></tr></table></ItemTemplate><HeaderStyle HorizontalAlign="Center" /> </asp:DataList>

2、CheckBox1_CheckedChanged函數(shù)

protected void CheckBox1_CheckedChanged(object sender, EventArgs e) {RememberOldValues(); }

3、RememberOldValues()函數(shù)
using System.Collections;public void RememberOldValues() {ArrayList categoryIDList = new ArrayList();if (Session[subTable] != null){categoryIDList = (ArrayList)Session[subTable];}int index = 0;foreach (DataListItem item in dlNews.Items){index = item.ItemIndex + (Int32.Parse(labPage.Text) - 1) * 7;bool result = ((CheckBox)item.FindControl("CheckBox1")).Checked;if (result){if (!categoryIDList.Contains(index)){categoryIDList.Add(index);}}else{categoryIDList.Remove(index);}}if (categoryIDList != null && categoryIDList.Count > 0){Session[subTable] = categoryIDList;} }其中:labPage.Text為當(dāng)前頁(yè),數(shù)字“7”為一頁(yè)顯示的數(shù)量

4、復(fù)現(xiàn)保存的選擇結(jié)果
private void RePopulateValues() {ArrayList categoryIDList = (ArrayList)Session[subTable];if (categoryIDList != null && categoryIDList.Count > 0){foreach (DataListItem item in dlNews.Items){int index = item.ItemIndex;if (categoryIDList.Contains(index + (Int32.Parse(labPage.Text) - 1) * 7)){CheckBox myCheckBox = (CheckBox)item.FindControl("CheckBox1");myCheckBox.Checked = true;}}} } 此函數(shù)可以放在DataList的數(shù)據(jù)綁定函數(shù)中bind() protected void bind() {......RePopulateValues(); }

參考:
http://zxianf.blog.163.com/blog/static/301207012010101112317730/
Asp.Net獲取Session、Cookies、Application中值:
http://www.cnblogs.com/ZHF/archive/2009/11/12/1601486.html

轉(zhuǎn)載于:https://my.oschina.net/sxq0714/blog/63243

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的DataList分页,保存CheckBox控件状态的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。