|
-
December 25th, 2007, 10:59 PM
#1
A single check box to check/uncheck all checkbox in a datagrid view
Hi,
I am a new bee in ASP.NEt.
My coding is as below.I have a problem in checking whether the first checkbox is checked or unchecked and then check /unchecked all the other checkbox in the datagridview.
Code:
<script runat="server">
Sub CheckAll_Click(sender As Object, e As EventArgs)
Dim i As Integer
For i = 0 To dgv1.Rows.Count - 1
CType(dgv1.Rows(i).FindControl("chkAll"), CheckBox).Checked = True
Next
End Sub
</script>
<HeaderTemplate>
<asp:CheckBox id="chkAllq" runat="server" OnCheckedChanged="CheckAll_Click" >
</asp:CheckBox>
</HeaderTemplate>
My problem is how to fire the CheckAll_Click event when the checkbox is checked or unchecked.Does any one has idea on this?what should i put in instead of OnCheckedChanged as does not fire the event ?
Last edited by johnsonlim026; December 25th, 2007 at 11:22 PM.
-
December 26th, 2007, 01:02 PM
#2
Re: A single check box to check/uncheck all checkbox in a datagrid view
First of all, it looks like you are only setting all of the check boxes to true (don't have a way of setting them to false).
I'm not so good at VB, and you might need to make my code look more like VB, but I think your code needs to look like this:
Code:
Sub CheckAll_Click(sender As Object, e As EventArgs)
Dim i As Integer
Dim newValue As Bool
// this will determine if that one "master" checkbox is checked or not
// set a variable for either case
if (chkAll.checked)
newValue = true
else
newValue = false
// now assign that variable to each of the other checkboxes
For i = 0 To dgv1.Rows.Count - 1
dgv1.Rows(i).Checked = newValue
Next
End Sub
Is this what you are looking for?
C# - Visual Studio 2005
Frameworks 2.0
-
December 27th, 2007, 02:55 AM
#3
Re: A single check box to check/uncheck all checkbox in a datagrid view
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|