У меня есть gridview, в котором я добавил столбец флажка, используя поле шаблона (я хочу, чтобы пользователь мог установить / снять флажок. Я хочу иметь возможность заполнять флажки, но когда я пытаюсь привести столбец как флажок на событии RowDataBound, это ошибки. Я также не могу сделать FindControl из-за главной страницы (я думаю)
Любая помощь будет оценена!
RowDataBound:
if (e.Row.RowType == DataControlRowType.DataRow) {
var RowData = (ResponderResultViewClass)e.Row.DataItem;
// This control never gets found (due to the Masterpage I think)
CheckBox chkBox = (CheckBox)e.Row.FindControl("chkCertified");
// This throws an error saying "Can't convert LiteralControl to Checkbox
CheckBox cb = (CheckBox)e.Row.Cells[4].Controls[0];
Вот код aspx:
<asp:BoundField DataField="AnswerID" ControlStyle-Width="0" />
<asp:BoundField DataField="QuestionText" HeaderText="Question" />
<asp:BoundField DataField="AnswerText" HeaderText="Answer" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="QualifyingGroupName" HeaderText="Qualifying Group" />
<asp:TemplateField HeaderText="Cert">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkCertified" runat="server" />
</ItemTemplate>
</asp:TemplateField>