关于DataGridView的CheckBoxField模板“该字符串未被识别为有效的布尔值”的解决方案

原来的写法:   <asp:CheckBoxField DataField="IsInPaper" />,即直接绑定到一个字段上,不过出现了如下的错误:

该字符串未被识别为有效的布尔值。

解决方案如下:
将其改为模板列,按照如下方式:

1<asp:TemplateField HeaderText="选择">
2                                <ItemTemplate>
3                                    <asp:CheckBox ID="chkQuestInfo" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"IsInPaper").ToString()=="1"?true:false %>' Enabled="true" />
4                                </ItemTemplate>
5                            </asp:TemplateField>

问题即可搞定。
点个广告:
原文地址:https://www.cnblogs.com/hanxianlong/p/916778.html