选中一个CheckBox以检查所有复选框 [英] Check One CheckBox To Check All CheckBoxes

查看:62
本文介绍了选中一个CheckBox以检查所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataGrid中的所有行(包括Header)都附带了一个CheckBox的
。我希望当选中Header中的CheckBox时,

然后应自动检查所有CheckBoxes。我将Header中的CheckBox的

AutoPostBack属性设置为True& am

在这个

CheckBox的CheckedChanged事件中调用一个名为''CheckAllRows'的子命令。 Header中的CheckBox存在于DataGrid&中的TemplateColumn的HeaderTemplate

中。其余的CheckBoxes驻留在同一TemplateColumn的ItemTemplate中的
。这是代码

(标题中CheckBox的ID是''chkHeader''&>

其余CheckBox的ID是''chkItem' '):


Sub CheckAllRows(ByVal obj As Object,ByVal ea As EventArgs)

Dim chkAllRows As CheckBox

Dim chkSelHeader作为CheckBox

Dim dgItem As DataGridItem


每个dgItem在dg1.Items中

If(dgItem.ItemType = ListItemType.Header )然后

chkSelHeader = dgItem.FindControl(" chkHeader")

Response.Write(" hello< br>")

如果(chkSelHeader.Checked)那么

If(dgItem.ItemType = ListItemType.Item或

dgItem.ItemType = ListItemType.AlternatingItem)那么

chkAllRows = dgItem.FindControl(" chkItem")

chkAllRows.Checked = True

结束如果

结束如果

结束如果

下一页

结束子


现在当我检查CheckBox中的时候标题,然后页面发布但

除了标题中的CheckBox之外没有CheckBoxes获得

选中。另请注意在第一个If条件下的Response.Write(hello< br>)行,即

。即使那条线也没有被执行

因为在回帖后,页面没有显示文字''你好''。


什么我在这里做错了吗?

All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named ''CheckAllRows'' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is ''chkHeader'' & the IDs of the
rest of the CheckBoxes are ''chkItem''):

Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem

For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub

Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn''t get executed
since after post back, the page doesn''t display the text ''hello''.

What am I doing wrong here?

推荐答案

我发现如果我摆脱了第一个检查的条件

是否ItemType为Header,即此行


If(dgItem.ItemType = ListItemType.Header)然后


& ;修改名为''CheckAllRows'的子中的For ... Next循环,这样


On Error Resume Next

for dgItem in dgMarks.Items

chkSelHeader = dgItem.FindControl(" chkHeader")

If(dgItem.ItemType = ListItemType.Item or dgItem.ItemType =

ListItemType .AlternatingItem)然后

chkAllRows = dgItem.FindControl(" chkItem")

If(chkSelHeader.Checked)然后

Response.Write( " checked< br>")

chkAllRows.Checked = True

Else

Response.Write(" unchecked< br>" ;)

chkAllRows.Checked = False

结束如果

结束如果

下一页


然后当选中Header中的CheckBox时,所有CheckBox都会得到

check&假设DataGrid有10行,文本''checked''

出现10个项目,但当我取消选中Header中的CheckBox以便

所有其他CheckBoxes获得未经检查,然后标题中的CheckBox取消选中,但所有其他CheckBox仍然保持检查状态&a​​mp;

页面仍显示已检查文本(&而不是文本''未选中'')10

次!


造成这种古怪行为的原因是什么?


此外,On Error Resume Next是一个必须的ASP.NET生成

出现以下错误:


对象引用未设置为对象的实例。


指向以下If条件:


如果(chkSelHeader.Checked)那么


有人可以告诉我,我做错了什么?这让我感动了

坚果!!
rn**@rediffmail.com 写道:
What I find is if I get rid of the first If condition which checks
whether the ItemType is Header or not i.e. this line

If (dgItem.ItemType = ListItemType.Header) Then

& modify the For...Next loop in the sub named ''CheckAllRows'' like this

On Error Resume Next
For Each dgItem In dgMarks.Items
chkSelHeader = dgItem.FindControl("chkHeader")
If (dgItem.ItemType = ListItemType.Item Or dgItem.ItemType =
ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
If (chkSelHeader.Checked) Then
Response.Write("checked<br>")
chkAllRows.Checked = True
Else
Response.Write("unchecked<br>")
chkAllRows.Checked = False
End If
End If
Next

then when the CheckBox in the Header is checked, all the CheckBoxes get
checked & assuming that the DataGrid has 10 rows, the text ''checked''
appears 10 items but when I uncheck the CheckBox in the Header so that
all the other CheckBoxes get unchecked, then the CheckBox in the header
gets unchecked but all the other CheckBoxes still remain checked & the
page still displays the text ''checked'' (& not the text ''unchecked'') 10
times!

What''s causing this eccentric behavior?

Moreover, the ''On Error Resume Next'' is a must else ASP.NET generates
the following error:

Object reference not set to an instance of an object.

pointing to the following If condition:

If (chkSelHeader.Checked) Then

Can someone please tell me what am I doing wrong? This is driving me
nuts!!
rn**@rediffmail.com wrote:

DataGrid中的所有行(包括Header)都附带

a CheckBox。我希望当选中Header中的CheckBox时,

然后应自动检查所有CheckBoxes。我将Header中的CheckBox的

AutoPostBack属性设置为True& am

在这个

CheckBox的CheckedChanged事件中调用一个名为''CheckAllRows'的子命令。 Header中的CheckBox存在于DataGrid&中的TemplateColumn的HeaderTemplate

中。其余的CheckBoxes驻留在同一TemplateColumn的ItemTemplate中的
。这是代码

(标题中CheckBox的ID是''chkHeader''&>

其余CheckBox的ID是''chkItem' '):


Sub CheckAllRows(ByVal obj As Object,ByVal ea As EventArgs)

Dim chkAllRows As CheckBox

Dim chkSelHeader作为CheckBox

Dim dgItem As DataGridItem


每个dgItem在dg1.Items中

If(dgItem.ItemType = ListItemType.Header )然后

chkSelHeader = dgItem.FindControl(" chkHeader")

Response.Write(" hello< br>")

如果(chkSelHeader.Checked)那么

If(dgItem.ItemType = ListItemType.Item或

dgItem.ItemType = ListItemType.AlternatingItem)那么

chkAllRows = dgItem.FindControl(" chkItem")

chkAllRows.Checked = True

En d如果

结束如果

结束如果

下一页

结束子


现在当我检查Header中的CheckBox时,页面发布但是

除了Header中的CheckBox之外没有CheckBoxes获得

选中。另请注意在第一个If条件下的Response.Write(hello< br>)行,即

。即使那条线也没有被执行

因为在回帖后,页面没有显示文字''你好''。


什么我在这里做错了吗?
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named ''CheckAllRows'' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is ''chkHeader'' & the IDs of the
rest of the CheckBoxes are ''chkItem''):

Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem

For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub

Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn''t get executed
since after post back, the page doesn''t display the text ''hello''.

What am I doing wrong here?



rn**@rediffmail.com 写道:

我发现如果我摆脱了检查

的第一个If条件是否ItemType是Header,即line


if(dgItem.ItemType = ListItemType.Header)那么


&修改名为''CheckAllRows'的子中的For ... Next循环,这样


On Error Resume Next

for dgItem in dgMarks.Items

chkSelHeader = dgItem.FindControl(" chkHeader")

If(dgItem.ItemType = ListItemType.Item or dgItem.ItemType =

ListItemType .AlternatingItem)然后

chkAllRows = dgItem.FindControl(" chkItem")

If(chkSelHeader.Checked)然后

Response.Write( " checked< br>")

chkAllRows.Checked = True

Else

Response.Write(" unchecked< br>" ;)

chkAllRows.Checked = False

结束如果

结束如果

下一页


然后当选中Header中的CheckBox时,所有CheckBox都会得到

check&假设DataGrid有10行,文本''checked''

出现10个项目,但当我取消选中Header中的CheckBox以便

所有其他CheckBoxes获得未经检查,然后标题中的CheckBox取消选中,但所有其他CheckBox仍然保持检查状态&a​​mp;

页面仍显示已检查文本(&而不是文本''未选中'')10

次!


造成这种古怪行为的原因是什么?


此外,On Error Resume Next是一个必须的ASP.NET生成

出现以下错误:


对象引用未设置为对象的实例。


指向以下If条件:


如果(chkSelHeader.Checked)那么


有人可以告诉我,我做错了什么?这让我感动了

坚果!!
rn**@rediffmail.com 写道:

DataGrid中的所有行(包括Header)都附带

a CheckBox。我希望当选中Header中的CheckBox时,

然后应自动检查所有CheckBoxes。我将Header中的CheckBox的

AutoPostBack属性设置为True& am

在这个

CheckBox的CheckedChanged事件中调用一个名为''CheckAllRows'的子命令。 Header中的CheckBox存在于DataGrid&中的TemplateColumn的HeaderTemplate

中。其余的CheckBoxes驻留在同一TemplateColumn的ItemTemplate中的
。这是代码

(标题中CheckBox的ID是''chkHeader''&>

其余CheckBox的ID是''chkItem' '):


Sub CheckAllRows(ByVal obj As Object,ByVal ea As EventArgs)

Dim chkAllRows As CheckBox

Dim chkSelHeader作为CheckBox

Dim dgItem As DataGridItem


每个dgItem在dg1.Items中

If(dgItem.ItemType = ListItemType.Header )然后

chkSelHeader = dgItem.FindControl(" chkHeader")

Response.Write(" hello< br>")

如果(chkSelHeader.Checked)那么

If(dgItem.ItemType = ListItemType.Item或

dgItem.ItemType = ListItemType.AlternatingItem)那么

chkAllRows = dgItem.FindControl(" chkItem")

chkAllRows.Checked = True

结束如果

结束如果

结束如果

下一页

结束子


现在当我检查Header中的CheckBox时,页面发布但是

除了Header中的CheckBox之外没有CheckBoxes获得

选中。另请注意在第一个If条件下的Response.Write(hello< br>)行,即

。即使那条线也没有被执行

因为在回帖后,页面没有显示文字''你好''。


什么我在这里做错了吗?
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named ''CheckAllRows'' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is ''chkHeader'' & the IDs of the
rest of the CheckBoxes are ''chkItem''):

Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem

For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub

Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn''t get executed
since after post back, the page doesn''t display the text ''hello''.

What am I doing wrong here?



hi ....使用这个java脚本,你会得到你想要的东西......在这里如果

你检查标题复选框然后所有网格的复选框将被

检查,当你取消选中标题复选框,然后在网格中取消选中所有

复选框

< script language =" JavaScript">


此函数检查标题状态的所有复选框

复选框

函数CheckAll(checkAllBox)

{

var frm = document.Form1;

var ChkState = checkAllBox。检查;


for(i = 0; i< frm.length; i ++)

{

e = frm.elements [ i];

if(e.type ==''checkbox''&& e.name.indexOf(''Id'')!= -1)

e.checked = ChkState;

}


}


此函数检查标题复选框所有复选框的状态基础

...如果全部为ch检查eckbox然后标题

复选框被选中

函数CheckChanged()

{

var frm = document .Form1;

var boolAllChecked;

boolAllChecked = true;


for(i = 0; i< frm.length; i ++)

{

e = frm.elements [i];


if(e.type == ''复选框''&& e.name.indexOf(''Id'')!= -1)


if(e.checked == false)

{

boolAllChecked = false;

休息;

}

}


for(i = 0; i< frm.length; i ++)

{

e = frm.elements [i];


if(e.type ==''checkbox''&& e.name.indexOf(''checkAll'')!= -1)

{

if(boolAllChecked == false)

e.checked = false;

else

e.checked = true;

休息;

}

}

}

< / script>


在< head>< / headand中写这个来自html

代码的函数并使用网格中的html复选框使用

onclick =" checkchanged"等等...你必须有回复

属性false所有复选框

hi....use this java script and you''ll have what you want...in this if
you check header checkbox then all the checkbox of the grid will be
checked and when you uncheck the header checkbox then have all the
checkboxes unchecked in the grid
<script language="JavaScript">

This function checks all the checkbox on the state of the header
checkbox
function CheckAll( checkAllBox )
{
var frm = document.Form1;
var ChkState=checkAllBox.checked;

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];
if(e.type==''checkbox'' && e.name.indexOf(''Id'') != -1)
e.checked= ChkState ;
}

}

This function checks the header checkbox on the basis of the state of
all the checkboxes ...if all checkboxes are checked then the header
checkbox is checked
function CheckChanged()
{
var frm = document.Form1;
var boolAllChecked;
boolAllChecked=true;

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];

if ( e.type==''checkbox'' && e.name.indexOf(''Id'') != -1 )

if(e.checked== false)
{
boolAllChecked=false;
break;
}
}

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];

if ( e.type==''checkbox'' && e.name.indexOf(''checkAll'') != -1 )
{
if( boolAllChecked==false)
e.checked= false ;
else
e.checked= true;
break;
}
}
}
</script>

write this within <head></headand call the function from the html
code and use the html checkbox in the grid and use
onclick="checkchanged" and so on...and you must have the postback
property false of the all checkboxes


是的Nil ...我知道这可以用JavaScript完成,但我确实更喜欢使用ASP.NET来做这件事。让我看看......如果我最终没有使用ASP.NET,我将恢复使用JavaScript来添加

功能。

nil写道:
Yeah Nil....I know this can be done using JavaScript but I did prefer
doing it using ASP.NET. Let me see......if I finally fail to do it
using ASP.NET, I will revert back to JavaScript to add that
functionality.
nil wrote:
rn**@rediffmail.com 写道:
rn**@rediffmail.com wrote:

我发现如果我摆脱了检查

的第一个If条件是否ItemType是Header,即此行


如果(dgItem.ItemType = ListItemType.Header)那么


&修改名为''CheckAllRows'的子中的For ... Next循环,这样


On Error Resume Next

for dgItem in dgMarks.Items

chkSelHeader = dgItem.FindControl(" chkHeader")

If(dgItem.ItemType = ListItemType.Item or dgItem.ItemType =

ListItemType .AlternatingItem)然后

chkAllRows = dgItem.FindControl(" chkItem")

If(chkSelHeader.Checked)然后

Response.Write( " checked< br>")

chkAllRows.Checked = True

Else

Response.Write(" unchecked< br>" ;)

chkAllRows.Checked = False

结束如果

结束如果

下一页


然后当选中Header中的CheckBox时,所有CheckBox都会得到

check&假设DataGrid有10行,文本''checked''

出现10个项目,但当我取消选中Header中的CheckBox以便

所有其他CheckBoxes获得未经检查,然后标题中的CheckBox取消选中,但所有其他CheckBox仍然保持检查状态&a​​mp;

页面仍显示已检查文本(&而不是文本''未选中'')10

次!


造成这种古怪行为的原因是什么?


此外,On Error Resume Next是一个必须的ASP.NET生成

出现以下错误:


对象引用未设置为对象的实例。


指向以下If条件:


如果(chkSelHeader.Checked)那么


有人可以告诉我,我做错了什么?这让我感动了

坚果!!
rn**@rediffmail.com 写道:

DataGrid中的所有行(包括Header)都附带

a CheckBox。我希望当选中Header中的CheckBox时,

然后应自动检查所有CheckBoxes。我将Header中的CheckBox的

AutoPostBack属性设置为True& am

在这个

CheckBox的CheckedChanged事件中调用一个名为''CheckAllRows'的子命令。 Header中的CheckBox存在于DataGrid&中的TemplateColumn的HeaderTemplate

中。其余的CheckBoxes驻留在同一TemplateColumn的ItemTemplate中的
。这是代码

(标题中CheckBox的ID是''chkHeader''&>

其余CheckBox的ID是''chkItem' '):

>

Sub CheckAllRows(ByVal obj As Object,ByVal ea As EventArgs)

Dim chkAllRows As CheckBox

Dim chkSelHeader作为CheckBox

Dim dgItem As DataGridItem

>

每个dgItem在dg1.Items

If(dgItem.ItemType = ListItemType.Header)然后

chkSelHeader = dgItem.FindControl(" chkHeader")

Response.Write(" hello< br> ;")

if(chkSelHeader.Checked)然后

If(dgItem.ItemType = ListItemType.Item或

dgItem.ItemType = ListItemType .AlternatingItem)然后

chkAllRows = dgItem.FindControl(" chkItem")

chkAllRows.Checked =真实

结束如果

结束如果

结束如果

下一页

结束Sub

>

现在,当我检查Header中的CheckBox时,页面发布但是除了CheckBox之外,没有任何CheckBox在标题中获得

检查。另请注意在第一个If条件下的Response.Write(hello< br>)行,即

。即使该行也没有被执行

,因为在回帖后,该页面没有显示文本''你好''。

>

我在这里做错了什么?
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named ''CheckAllRows'' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is ''chkHeader'' & the IDs of the
rest of the CheckBoxes are ''chkItem''):
>
Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem
>
For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub
>
Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn''t get executed
since after post back, the page doesn''t display the text ''hello''.
>
What am I doing wrong here?



hi ....使用这个java脚本,你会得到你想要的...在这个如果

你检查标题复选框然后所有网格的复选框将被

检查,当你取消选中标题复选框,然后在网格中取消选中所有

复选框

< script language =" JavaScript">


此函数检查标题状态的所有复选框

复选框

函数CheckAll(checkAllBox)

{

var frm = document.Form1;

var ChkState = checkAllBox。检查;


for(i = 0; i< frm.length; i ++)

{

e = frm.elements [ i];

if(e.type ==''checkbox''&& e.name.indexOf(''Id'')!= -1)

e.checked = ChkState;

}


}


此函数检查标题复选框

所有复选框...如果选中所有复选框,则选中标题

复选框

函数CheckChanged()

{

var frm = document.Form1;

var boolAllChecked;

boolAllChecked = true;


代表(i = 0; i< frm.length; i ++)

{

e = frm.elements [i];


if(e.type == ''复选框''&& e.name.indexOf(''Id'')!= -1)


if(e.checked == false)

{

boolAllChecked = false;

休息;

}

}


for(i = 0; i< frm.length; i ++)

{

e = frm.elements [i];


if(e.type ==''checkbox''&& e.name.indexOf(''checkAll'')!= -1)

{

if(boolAllChecked == false)

e.checked = false;

else

e.checked = true;

休息;

}

}

}

< / script>


在< head>< / headand中写这个来自html

代码的函数并使用网格中的html复选框使用

onclick =" checkchanged&qu OT;等等...你必须有回复

属性false所有复选框


hi....use this java script and you''ll have what you want...in this if
you check header checkbox then all the checkbox of the grid will be
checked and when you uncheck the header checkbox then have all the
checkboxes unchecked in the grid
<script language="JavaScript">

This function checks all the checkbox on the state of the header
checkbox
function CheckAll( checkAllBox )
{
var frm = document.Form1;
var ChkState=checkAllBox.checked;

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];
if(e.type==''checkbox'' && e.name.indexOf(''Id'') != -1)
e.checked= ChkState ;
}

}

This function checks the header checkbox on the basis of the state of
all the checkboxes ...if all checkboxes are checked then the header
checkbox is checked
function CheckChanged()
{
var frm = document.Form1;
var boolAllChecked;
boolAllChecked=true;

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];

if ( e.type==''checkbox'' && e.name.indexOf(''Id'') != -1 )

if(e.checked== false)
{
boolAllChecked=false;
break;
}
}

for(i=0;i< frm.length;i++)
{
e=frm.elements[i];

if ( e.type==''checkbox'' && e.name.indexOf(''checkAll'') != -1 )
{
if( boolAllChecked==false)
e.checked= false ;
else
e.checked= true;
break;
}
}
}
</script>

write this within <head></headand call the function from the html
code and use the html checkbox in the grid and use
onclick="checkchanged" and so on...and you must have the postback
property false of the all checkboxes


这篇关于选中一个CheckBox以检查所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆