0

Hi,

I have a gridview with checkboxes in the 3rd column. I am trying to work out when they are selected. I have the following code:

foreach (GridViewRowInfo dr in gvMovies.Rows)   
if (dr.Cells[2].Value = true) MessageBox.Show("Row " + dr.Index + " selected");

I get the following error: Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?)
I have tried the following but nothing has worked:

foreach (GridViewRowInfo dr in gvMovies.Rows)   
if ((bool)dr.Cells[2].Value = true) MessageBox.Show("Row " + dr.Index + " selected");
foreach (GridViewRowInfo dr in gvMovies.Rows)   
if (Convert.ToBoolean(dr.Cells[2].Value) = true) MessageBox.Show(dr.Cells[2].Value + " Rows " + dr.Index + " selected");

Thanks for any replies
Jay

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JayWeb
0

I found the answer:

foreach (GridViewRowInfo dr in gvMovies.Rows)   
if (dr.Cells[2].Value == true) MessageBox.Show("Row " + dr.Index + " selected");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.