DataList分页,保存CheckBox控件状态
生活随笔
收集整理的這篇文章主要介紹了
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ù)
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)題。
- 上一篇: SQL Server 2000/2005
- 下一篇: Process Explorer工具介绍