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.Controls;
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;
Remember to click on Mark as answer on the post that helped you