1
這是字符串被分配到一個布爾值屬性的行:不能鍵入「串」隱式轉換爲數據「布爾」結合(GridView控件)
chkreputative.Checked = gvmanufacturers.DataKeys[rowindex]["IsReputative"].ToString();
這是字符串被分配到一個布爾值屬性的行:不能鍵入「串」隱式轉換爲數據「布爾」結合(GridView控件)
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"]);