从GridView更新数据库时,获取复选框值为一或零 [英] Get checkbox value to be one or zero when updating database from gridview

查看:75
本文介绍了从GridView更新数据库时,获取复选框值为一或零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是一名C#初学者,需要一些关于gridview的帮助.我有一个带有3个编辑模板的gridview ...一个文本框(默认),一个下拉列表和一些复选框.在数据库表中,有一列,其数据类型为tinyint.如果需要检查数据库的值,那么我如何才能得到它的复选框值,如果选中则为1,如果未选中,则为0.

Hi all, I am a beginner c# programmer and need some help with a gridview. I have a gridview that has 3 edit templates...a textbox(default) a dropdownlist and a few checkboxes. In the database table there is a column thats datatype is tinyint. How when i need to update the database can i get the checkbox value if its checked then it gives one and if it isnt checked gives a 0.

推荐答案


报价:

在数据库表中,有一列的数据类型为tinyint

In the database table there is a column thats datatype is tinyint


将数据库列从tinyint更改为bit并发送布尔值


Change the database column from tinyint to bit and send the boolean value

报价:

1)true:如果选中了复选框
2)flase:如果未选中复选框

1) true: if checkbox is checked
2) flase:if checkbox is not checked


从前端.您的问题将得到解决.

--mit


from front-end. Your problem will be solved.

--Amit


String chk1 = ((System.Web.UI.WebControls.CheckBox)(row.Cells[4].Controls[1])).Checked ? "1" : "0";

如果选中则返回1,如果未选中则返回0

this will return 1 if checked and 0 if it wasnt checked


这篇关于从GridView更新数据库时,获取复选框值为一或零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆