这是将String分配给布尔属性的行:
chkreputative.Checked = gvmanufacturers.DataKeys[rowindex]["IsReputative"].ToString();
答案 0 :(得分:2)
摆脱ToString()
电话,并应用正确的演员表。您正尝试为String
值分配Boolean
值,这就是您获得例外的原因。
根据DataKeys
对象的类型,您可以尝试以下某些操作:
chkreputative.Checked = (bool)gvmanufacturers.DataKeys[rowindex]["IsReputative"];
chkreputative.Checked = Boolean.Parse(gvmanufacturers.DataKeys[rowindex]["IsReputative"]);
chkreputative.Checked = Convert.ToBoolean(gvmanufacturers.DataKeys[rowindex]["IsReputative"]);