javascript实现datagrid客户端checkbox列的全选,反选

1ExpandedBlockStart.gifContractedBlock.gif /**/ /* 分页
2InBlock.gif 参数说明:
3InBlock.gif prefix:前缀;chkAll:全选框;chkSingle:单选框ID
4InBlock.gif
5InBlock.gif 使用方法:
6InBlock.gif if(e.Item.ItemType == ListItemType.Header)
7InBlock.gif {
8InBlock.gif ((CheckBox)e.Item.Cells[1].FindControl("chkAll")).Attributes.Add("onclick","CheckAll('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle');");
9InBlock.gif }
10ExpandedBlockEnd.gif*/
11 None.gif function CheckAll(prefix,chkAll,chkSingle)
12 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
13InBlock.gifvar indexChkAll;
14InBlock.gifif(prefix.length != 0)
15ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
16InBlock.gif indexChkAll = prefix + "__ctl2_" + chkAll;
17ExpandedSubBlockEnd.gif }
18InBlock.gifelse
19ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
20InBlock.gif indexChkAll = chkAll;
21ExpandedSubBlockEnd.gif }
22InBlock.gifvar objChkAll = document.getElementById(indexChkAll);
23InBlock.gifvar tempObj;
24InBlock.giffor(var i=0;i<document.forms[0].elements.length;i++)
25ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
26InBlock.gif tempObj = document.forms[0].elements[i];
27InBlock.gifif(tempObj.type == "checkbox" && tempObj.id != indexChkAll && tempObj.id.indexOf(chkSingle) != -1)
28ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
29InBlock.gif tempObj.checked = objChkAll.checked;
30ExpandedSubBlockEnd.gif }
31ExpandedSubBlockEnd.gif }
32ExpandedBlockEnd.gif}
33 ExpandedBlockStart.gif ContractedBlock.gif /**/ /* 分页
34InBlock.gif 参数说明:
35InBlock.gif prefix:前缀;chkAll:全选框;chkSingle:单选框ID
36InBlock.gif
37InBlock.gif 使用方法:
38InBlock.gif if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
39InBlock.gif {
40InBlock.gif ((CheckBox)e.Item.Cells[1].FindControl("chkSingle")).Attributes.Add("onclick","CheckSingle('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle');");
41InBlock.gif }
42ExpandedBlockEnd.gif*/
43 None.gif function CheckSingle(prefix,chkAll,chkSingle)
44 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
45InBlock.gifvar indexChkAll;
46InBlock.gifif(prefix.length != 0)
47ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
48InBlock.gif indexChkAll = prefix + "__ctl2_" + chkAll;
49ExpandedSubBlockEnd.gif }
50InBlock.gifelse
51ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
52InBlock.gif indexChkAll = chkAll;
53ExpandedSubBlockEnd.gif }
54InBlock.gifvar objChkAll = document.getElementById(indexChkAll);
55InBlock.gifvar tempObj;
56InBlock.gifvar allCount = 0;
57InBlock.gifvar checkCount = 0;
58InBlock.giffor(var i=0;i<document.forms[0].elements.length;i++)
59ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
60InBlock.gif tempObj = document.forms[0].elements[i];
61InBlock.gifif(tempObj.type == "checkbox" && tempObj.id != indexChkAll && tempObj.id.indexOf(chkSingle) != -1)
62ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
63InBlock.gifif(tempObj.checked)
64ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
65InBlock.gif checkCount++;
66ExpandedSubBlockEnd.gif }
67InBlock.gifelse
68ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
69InBlock.gif objChkAll.checked = false;
70InBlock.gif//break;
71ExpandedSubBlockEnd.gif }
72InBlock.gif allCount++;
73ExpandedSubBlockEnd.gif }
74ExpandedSubBlockEnd.gif }
75InBlock.gifif(checkCount != allCount)
76ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
77InBlock.gif objChkAll.checked = false;
78ExpandedSubBlockEnd.gif }
79InBlock.gifelse
80ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
81InBlock.gifif(allCount != 0)
82ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
83InBlock.gif objChkAll.checked = true;
84ExpandedSubBlockEnd.gif }
85ExpandedSubBlockEnd.gif }
86ExpandedBlockEnd.gif}
87 ExpandedBlockStart.gif ContractedBlock.gif /**/ /*
88InBlock.gif 参数说明:
89InBlock.gif prefix:前缀;chkAll:全选框;chkSingle:单选框ID
90InBlock.gif type:1【全选】,2【反选】,3【取消】
91InBlock.gif
92InBlock.gif 使用方法:
93InBlock.gif this.btnSelectAll.Attributes.Add("onClick","CheckType('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle',1);");
94InBlock.gif this.btnUnSelectAll.Attributes.Add("onClick","CheckType('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle',2);");
95InBlock.gif this.btnCancelSelect.Attributes.Add("onClick","CheckType('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle',3);");
96ExpandedBlockEnd.gif*/
97 None.gif function CheckType(prefix,chkAll,chkSingle,type)
98 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
99InBlock.gifvar indexChkAll;
100InBlock.gifif(prefix.length != 0)
101ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
102InBlock.gif indexChkAll = prefix + "__ctl2_" + chkAll;
103ExpandedSubBlockEnd.gif }
104InBlock.gifelse
105ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
106InBlock.gif indexChkAll = chkAll;
107ExpandedSubBlockEnd.gif }
108InBlock.gifvar objChkAll = document.getElementById(indexChkAll);
109InBlock.gifvar tempObj;
110InBlock.gifvar allCount = 0;
111InBlock.gifvar checkCount = 0;
112InBlock.giffor(var i=0;i<document.forms[0].elements.length;i++)
113ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
114InBlock.gif tempObj = document.forms[0].elements[i];
115InBlock.gifif(tempObj.type == "checkbox" && tempObj.id != indexChkAll && tempObj.id.indexOf(chkSingle) != -1)
116ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
117InBlock.gifswitch(type)
118ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
119InBlock.gifcase 1:
120InBlock.gif tempObj.checked = true;
121InBlock.gifbreak;
122InBlock.gifcase 2:
123InBlock.gif tempObj.checked = !tempObj.checked;
124InBlock.gifbreak;
125InBlock.gifcase 3:
126InBlock.gif tempObj.checked = false;
127InBlock.gifbreak;
128ExpandedSubBlockEnd.gif }
129InBlock.gifif(tempObj.checked)
130ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
131InBlock.gif checkCount++;
132ExpandedSubBlockEnd.gif }
133InBlock.gif allCount++;
134ExpandedSubBlockEnd.gif }
135ExpandedSubBlockEnd.gif }
136InBlock.gifif(checkCount != allCount)
137ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
138InBlock.gif objChkAll.checked = false;
139ExpandedSubBlockEnd.gif }
140InBlock.gifelse
141ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
142InBlock.gifif(allCount != 0)
143ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
144InBlock.gif objChkAll.checked = true;
145ExpandedSubBlockEnd.gif }
146ExpandedSubBlockEnd.gif }
147InBlock.gif window.event.returnValue = false;
148InBlock.gifreturn false;
149ExpandedBlockEnd.gif}
150 None.gif
151 ExpandedBlockStart.gif ContractedBlock.gif /**/ /*
152InBlock.gif 参数说明:
153InBlock.gif prefix:前缀;chkAll:全选框;chkSingle:单选框ID
154InBlock.gif
155InBlock.gif 使用方法:
156InBlock.gif this.btnDelete.Attributes.Add("onClick","SubmitCheckBox('" + this.dg.ClientID.ToString() + "','chkAll','chkSingle');");
157ExpandedBlockEnd.gif*/
158 None.gif function SubmitCheckBox(prefix,chkAll,chkSingle,msg)
159 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
160InBlock.gifvar indexChkAll;
161InBlock.gifif(prefix.length != 0)
162ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
163InBlock.gif indexChkAll = prefix + "__ctl2_" + chkAll;
164ExpandedSubBlockEnd.gif }
165InBlock.gifelse
166ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
167InBlock.gif indexChkAll = chkAll;
168ExpandedSubBlockEnd.gif }
169InBlock.gifvar objChkAll = document.getElementById(indexChkAll);
170InBlock.gif
171InBlock.gifvar tempObj;
172InBlock.gifvar allCount = 0;
173InBlock.gifvar checkCount = 0;
174InBlock.giffor(var i=0;i<document.forms[0].elements.length;i++)
175ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
176InBlock.gif tempObj = document.forms[0].elements[i];
177InBlock.gifif(tempObj.type == "checkbox" && tempObj.id != indexChkAll && tempObj.id.indexOf(chkSingle) != -1)
178ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
179InBlock.gifif(tempObj.checked)
180ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
181InBlock.gif checkCount++;
182ExpandedSubBlockEnd.gif }
183InBlock.gif allCount++;
184ExpandedSubBlockEnd.gif }
185ExpandedSubBlockEnd.gif }
186InBlock.gifif(allCount == 0) //没有数据
187ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
188InBlock.gif window.alert("当前没有" + msg + "可供删除dot.gif");
189InBlock.gif window.event.returnValue = false;
190InBlock.gifreturn false;
191ExpandedSubBlockEnd.gif }
192InBlock.gifelse
193ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
194InBlock.gifif(checkCount == 0)
195ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
196InBlock.gif window.alert("没有选中要删除的" + msg + "dot.gif");
197InBlock.gif window.event.returnValue = false;
198InBlock.gifreturn false;
199ExpandedSubBlockEnd.gif }
200InBlock.gifelse
201ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
202InBlock.gif//if(window.confirm("确定要删除当前选中的【" + checkCount.toString() + "】项吗?") == false)
203InBlock.gif if(window.confirm("确定要删除当前选中的" + msg + "吗?") == false)
204ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
205InBlock.gif window.event.returnValue = false;
206InBlock.gifreturn false;
207ExpandedSubBlockEnd.gif }
208ExpandedSubBlockEnd.gif }
209ExpandedSubBlockEnd.gif }
210ExpandedBlockEnd.gif}



本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/11/07/270449.html,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值