Re: Checkbox Inside Gridview
Hello,
Couple things I would suggest here...
1. Set a default value on the Active field in the database such that whenever a row is added, regardless of whether a value is provided, the Active field will always be given a true or a false, depending on your requirements.
2. What is the data type of the Active field? Why do you need to convert it in the first place?
3. Don't do the conversion logic in the ASPX markup, this is the wrong place to do it. Doing it this way means that you are closely coupling the UI to the Business Logic, which is never a good place to be in
4. Try to understand the error message that you are getting back. Let me try to explain...
The Convert.ToBoolean method has a number of overrides, meaning that it can accept a number of different types, and it will try to figure out what the boolean equivalent is:
http://msdn.microsoft.com/en-us/libr...toboolean.aspx
You will notice from the above list, that a DBNull value is not mentioned. The Convert.ToBoolean method doesn't know how to convert from a DBNull to a boolean, and that is what you are giving it. In order to correct this, you are going to need to first check whether or not the value that you are getting is a DBNull, if it is, then take appropriate action, i.e. default it to false, or to true. If it isn't, carry on with the conversion.
Hope that helps!
Gary
Re: Checkbox Inside Gridview
ITS DONE!!!!!
You can handle the NULL value in Query itself and can return 0 or false from there for example
Code:
Select isNull(ColName,'False') as [Active] from INSERT_QUESTION
Re: Checkbox Inside Gridview
Hello,
Yes, that is certainly an option.
I would still suggest that correct handling of the data within your code is something that you need to look into.
Thanks
Gary