CheckBoxes in DataGrid

R

rn5a

The first column of a DataGrid has a CheckBox for all the rows. I want
that when users check a CheckBox, the BackColor of that entire row in
the DataGrid should change to a different color. To implement this, if
I am not mistaken, I HAVE TO post the Form first i.e. set the
AutoPostBack property of the CheckBox to True. Without posting the
Form, I don't think the BackColor of the checked row can be changed
using ASP.NET, isn't it?

Of course, it can be done using some client side script like JavaScript
but to do it using ASP.NET, I have to post the Form first, isn't it?
 
N

Newbie Coder

Yesterday, I done a Google search for the same thing

If you go to http://www.google.com & search for

"CheckListBox", "VB.NET" (with quotes & comma) you will find many examples
of what you are looking for
 
R

rn5a

I am not looking out for a code snippet to change the BackColor of a
row in the DataGrid which is checked; I have already succeeded in doing
that but I did it by setting the AutoPostBack property of the
CheckBoxes in the DataGrid to True. In other words, I am highlighting
the checked row/s using ASP.NET.

What I would like to know is can the same functionality be added to the
CheckBoxes by setting the AutoPostBack property of the CheckBoxes in
the DataGrid to False. I wouldn't like to use JavaScript (or any other
client-side script) to do that & prefer doing this using ASP.NET.

Even I had a look at a number of articles which show how to do this but
all the articles I have come across set AutoPostBack=True for the
CheckBoxes. Did you find any articles which does this by setting
AutoPostBack=False?
 
M

Mohsin Rizvi

Hello,

Well i'm afraid brother! but you have to use client side script to
fulfil your requirement.

In my opinion there are only two possibilities:

1. Post back & change gridrow color
2. Use a client side script

Unfortunately i could not think of any other way to change gridrow's
color.

Regards,
Mohsin Rizvi
 
N

nil

Mohsin said:
Hello,

Well i'm afraid brother! but you have to use client side script to
fulfil your requirement.

In my opinion there are only two possibilities:

1. Post back & change gridrow color
2. Use a client side script

Unfortunately i could not think of any other way to change gridrow's
color.

Regards,
Mohsin Rizvi

hey tell me how can i change the back color of checked checkbox in
grid...i did coding for checked box and it works fine when user checks
the checkbox in header of the grid then all
the checkbox in the grid is checked...if anyone tell me how to set
backcolor of the grid using javascript or any other thing then i'll be
useful...thanks a lot in advance
 
R

rn5a

Nil, this is how I did it (the sub named 'CheckChanged' is the
CheckedChanged event handler of the CheckBox & the AutoPostBack
property of the CheckBox has been set to True; 'chkItem' is the name of
the CheckBox in the DataGrid named 'dg1'):

Sub CheckChanged(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkSelItem As CheckBox
Dim dgItem As DataGridItem

For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Item Or dgItem.ItemType =
ListItemType.AlternatingItem) Then
chkSelItem = dgItem.FindControl("chkItem")
If (chkSelItem.Checked) Then
dgItem.BackColor = Drawing.Color.LightCyan
End If
End If
Next
End Sub

Hope this helps.....

I was just about to ask you how did you manage to check all the
CheckBoxes in a DataGrid when the CheckBox in the Header is checked but
found that you have already answered that.......
 
N

nil

Nil, this is how I did it (the sub named 'CheckChanged' is the
CheckedChanged event handler of the CheckBox & the AutoPostBack
property of the CheckBox has been set to True; 'chkItem' is the name of
the CheckBox in the DataGrid named 'dg1'):

Sub CheckChanged(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkSelItem As CheckBox
Dim dgItem As DataGridItem

For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Item Or dgItem.ItemType =
ListItemType.AlternatingItem) Then
chkSelItem = dgItem.FindControl("chkItem")
If (chkSelItem.Checked) Then
dgItem.BackColor = Drawing.Color.LightCyan
End If
End If
Next
End Sub

Hope this helps.....

I was just about to ask you how did you manage to check all the
CheckBoxes in a DataGrid when the CheckBox in the Header is checked but
found that you have already answered that.......


ya i used java script for that and it's work fine as i don't want page
to be refressh each time
 
N

nil

nil said:
ya i used java script for that and it's work fine as i don't want page
to be refressh each time



hello i have used java script so tell me how to do that in
javascript?thanks for the previous coding...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top