FindControl on GridView Cell returning null

S

saha

Group,

This is the problem I am facing (VS2005):

- I do a GridView1.DataSource = DataTable and GridView1.DataBind()
- then I add checkbox coltrols to a selected few cells of the GridView:

CheckBox cb = new checkBox();
cb.ID = "cbSelect";
GridView1.Rows[j].Cells[k].Controls.Add(cb);

Every thing works fine and I am able to see the checkboxes on screen.
The user is suppose to select the checkbox, which ever is applicable
and is suppose to click a button for further processing.

On click of the button, I try to fetch the checkBoxes by doing
FindControl on the appropriate cells:

CheckBox cb =
(CheckBox)GridView1.Rows[j].Cells[k].FindControl("cbSelect");

But I always get cb as null. Any idea what might be wrong here ?
Yes, on button click, I check for the controls *before* reassigning the
datasource again.

saha
--
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top