If we could have accessed the Bind method ,that implicitly performs two-way binding, in the code-behind then we could have just override the RowDatabound event and assigned the value to the gridview's checkbox control using the Bind method. But unfortunately the Bind is not available in ASP.Net 2.0 instead Eval only is available.

We could still achieve this in two simple and easy steps.
1. Wrap the Eval(fieldname) HTML code in a function eg: Checkvalue that checks the datafield value, performs transformations to True OR False values and assigns to Chekced property.

2. Override the RowUpdating event of gridview and update only the Checked property's value since the SQLDataSource that is bound to gridview will take care of remaining fields to update.

Please let me know if this has helped anyone solve the problem!!

Introduction

This is bit tricky but possible!!

When you try to assign expected boolean value to Checked property of a chekcbox using Eval or Bind methods in HTML the application throws exception - Specified cast is invalid.

The issue is about achieving Two-way binding with the checkbox!!

Actually we could assign the checked property using different methods eg: one way is to overriding the RowDatabound event of gridview.

Find the checkbox control from the selected gridviewdatarow object and assign the value using either Eval(fieldname) OR Container.DataItem(fieldname) methods.

But I am not sure how we would update this Checked property since the field would become ReadOnly. The SQlDataSource will not update this checkbox's Checked property value.

I know one method that uses less code and is easy. It has 2 steps as follows...

Step 1

We could instead assign the checked property by wrapping the Eval(fieldname) inside a function Checkvalue(Eval(fieldname)).

By performing above coding we would avoid the error - Specified cast is invalid.

Step 2

Then we need to override the gridview's RowUpdating event. In this event you can write code to get the newvalue of checkbox's checked property only. The Sqldatasource that is bound to gridview will pick up the other remaining fields new values, to update!!

Conclusion

If we could have accessed the Bind method,that implicitly performs two-way binding, in the code-behind then we could have just override the RowDatabound event and assigned the value to the gridview's checkbox control using the Bind method. But unfortunately the Bind is not available in ASP.Net 2.0 instead Eval only is available.

Instead the above code performs the magic of two-way binding for the checkbox.