object instantiation

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;
 
R

Robert Porter

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;
 
C

Carlos

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;

 
S

sloan

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;

...
 
C

Carlos

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;

 
L

Laurent Bugnion

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
 
C

Carlos

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

Thanks again!

Carlos.
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top