user2091742
user2091742

Reputation: 11

Cannot implicitly convert type 'string' to 'bool' in data binding(gridview)

This is the line where the String gets assigned to a boolean property:

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

Upvotes: 1

Views: 1214

Answers (1)

RoelF
RoelF

Reputation: 7573

Get rid of the ToString() call, and apply the correct cast. You are trying to assign a String value to a Boolean value, that's why you get the exception.

Depending on what type the DataKeys object is, you can try some of the following:

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

chkreputative.Checked = Boolean.Parse(gvmanufacturers.DataKeys[rowindex]["IsReputative"]);

chkreputative.Checked = Convert.ToBoolean(gvmanufacturers.DataKeys[rowindex]["IsReputative"]);

Upvotes: 2

Related Questions