如何使用CheckBox将数据插入GridView? [英] How to insert data to the GridView using CheckBox?

查看:73
本文介绍了如何使用CheckBox将数据插入GridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个GridView,并在其所有单元格中都放置了复选框.我要执行以下操作:
如果用户选中了该复选框,则表示是,它将存储在数据库中
否则,如果用户未选中该复选框,则表示否",无需将任何内容发布到数据库.

我知道我现在需要标识每个选中的复选框,并知道此选中的复选框位于哪个单元格下面.

关于如何做到这一点的任何想法?有人可以给我基本的代码吗?

Hello everybody,

I have a GridView and I put checkboxes inside all its cells. I want to do the following:
if the checkbox checked by the user, this means Yes which will be stored in the database
else, if the checkbox unchecked by the user, this means No and no need to post anything to the database.

I know I need now to identify each checked checkbox and know which cell this checked checkbox is underneath it.

Any idea about how to do that? Could anyone give me the basic piece of code for doing this?

推荐答案

尝试这个
for (int x = 0; x < grdview.Rows.Count; x++)
 {
 CheckBox chkDoc = (CheckBox) grdview.Rows[x].FindControl("chkDoc");

            if (chkDoc.Checked)
            {
                //apply your logic here
            }
        }


使用< asp:TemplateField></asp:TemplateField>然后在< ItemTemplate></ItemTemplate>中在GridView的范围内,将您的CheckBox代码...
use <asp:TemplateField></asp:TemplateField> then in the <ItemTemplate></ItemTemplate> scope of GridView, put your CheckBox code ...


这篇关于如何使用CheckBox将数据插入GridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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