2014年7月13日 星期日

[RESOLVED] Convert int to bool for CheckBox in Asp.Net GridView


Hi,


is it possible to bind a int-Value from DB to a Checkbox column in a gridview?


with TemplateField it's possible to show the data









The Function "Eval("..")" works fine for displaying the data in checkbox.


But when i Edit and Update a single row a Error is thrown:

CS0103: The Name 'Bind' can not be found....


Anyone an Idea?


Thanks





Flo Stony







Try this:




by the way why you are not use same in edititemtemplate?









Flo Stony






Are you using any datasource control to insert / edit ? If not than use Eval in edit template




Eval is one-way, read only databinding and Bind is two-way, read/write databinding. When we use some datasource i.e. SqlDataSource and inline editing in gridview than we need two way binding and we use Bind method.


Thanks






Try conversion in SQL


Checked='<%# Bind("BITCOLUMN") %>'

BITCOLUMN is Alias in select command, then use it as param name too in update/insert command


Select Command


SELECT CAST(INTCOLUMN as Bit) as BITCOLUMN

Update/Insert Parameter


UpdateCommand="UPDATE TBL SET INTCOLUMN=CAST(@BITCOLUMN as INT), ...">





沒有留言:

張貼留言