这是 String 分配给布尔属性的行:
chkreputative.Checked = gvmanufacturers.DataKeys[rowindex]["IsReputative"].ToString();
摆脱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"]);