getting access to gridview data to set a template column

Hello.  I have a gridview which contains a checkbox item template. I need to set this initially to checked if another bound boolean data item in the grid is true (i.e. ticked in the gridview).

Similarly, I have a dropdownlist whose selectedvalue I need to select to match a bound string data item in the grid.

How can I do this? FindControl seems to be a common method of access the data, but the bool and string items in the grid do not have an ID.

 So far, I've just managed to set the checkbox item template to true in the gridview RowCreated event as follows, but need to go further than this as described above.

CheckBox cb = (CheckBox)e.Row.FindControl("CompanySelector");

cb.Checked = true;

 Attempts like

cb.Checked = (bool)e.Row.Cells[3].Controls[0];

give errors.


Many Thanks,


10/25/2007 7:22:38 AM 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 2

Do this in the  RowDataBoung event instead of row creating and use the DataItem property of the current row to access the needed information.


CheckBox cb = (CheckBox)e.Row.FindControl("CompanySelector");

cb.Checked = true;

cb.Checked = ((UserClass)(e.Row.DataItem)).IsActive;

Hosam Kamel

Remember to click on Mark as answer on the post that helped you
10/25/2007 8:27:36 AM