1

这是 String 分配给布尔属性的行:

chkreputative.Checked = gvmanufacturers.DataKeys[rowindex]["IsReputative"].ToString();
4

1 回答 1

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"]);
于 2013-02-20T15:11:17.857 回答