object instantiation

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

Hi all,

I have the following code snipet that is causing an exception when
processing
a gridview with checkboxes How can I fix it ? Thanks in advance, Carlos.

GridViewRow row = GridView7.Rows;

bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
 
It would be helpful to know what the exception is?


Hi all,

I have the following code snipet that is causing an exception when
processing
a gridview with checkboxes How can I fix it ? Thanks in advance, Carlos.

GridViewRow row = GridView7.Rows;

bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
 
Hi Robert,

sure, and I am sorry. it is:

Object reference not set to an instance of an object

Thanks again,

Carlos.

Robert Porter said:
It would be helpful to know what the exception is?


Hi all,

I have the following code snipet that is causing an exception when
processing
a gridview with checkboxes How can I fix it ? Thanks in advance, Carlos.

GridViewRow row = GridView7.Rows;

bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

 
On that kind of situation, you need to break it apart, to figure out the
exact cause.

GridViewRow row = GridView7.Rows;

//is row null?

object abc = row.FindControl("chkSelect");

//is abc null?

CheckBox ccc = abc as CheckBox;

//is ccc null?

bool isChecked = ccc.Checked;

...
 
Thanks Sloan,

I inspected the gridview row count first, and I got 10,
then each particular row, and the instances were there.

any other suggestion?

Thanks again,

Carlos.

sloan said:
On that kind of situation, you need to break it apart, to figure out the
exact cause.

GridViewRow row = GridView7.Rows;

//is row null?

object abc = row.FindControl("chkSelect");

//is abc null?

CheckBox ccc = abc as CheckBox;

//is ccc null?

bool isChecked = ccc.Checked;

..





Carlos said:
Hi all,

I have the following code snipet that is causing an exception when
processing
a gridview with checkboxes How can I fix it ? Thanks in advance, Carlos.

GridViewRow row = GridView7.Rows;

bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

 
Hi,
Thanks Sloan,

I inspected the gridview row count first, and I got 10,
then each particular row, and the instances were there.

any other suggestion?

Thanks again,

Carlos.

Obviously, either "GridView7" or "row" are null, or "chkSelect" doesn't
exist. I think it's the later one. "Object not set" exceptions are
fairly easy to trace, though, especially in debug mode.

Set a breakpoint in your code, and inspect what
row.FindControl("chkSelect") evaluates to. I am pretty sure that it's
null. Maybe you mistyped the ID.

HTH,
Laurent
 
Thank you Laurent! that did it indeed, I had the 't' appearing double
in the control code.

Thanks again!

Carlos.
 
Back
Top