如何在ASP.Net中使用CheckBox获取所选的GridView行 [英] how to get the selected rows of GridView with CheckBox in ASP.Net

查看:192
本文介绍了如何在ASP.Net中使用CheckBox获取所选的GridView行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





想法是有一个按钮,当点击时,一个循环将在GridView Rows上执行。

在循环中我们将检查是否检查了该行的CheckBox,如果选中CheckBox,则检查
然后检查GridView行中的值

将被提取并插入到数据库表中。

i我正在使用3层架构。

请帮助。

谢谢。



The idea is to have a button which when clicked, a loop will be executed over GridView Rows.
Within the loop we will check whether the CheckBox for that row is checked,
if the CheckBox is checked then the Value from the GridView Rows that are checked
will be fetched and inserted into database table.
i am using 3 layered architecture.
please help.
Thanks.

推荐答案

您好,我们可以通过以下方式检查是否选中了复选框





Hi, here is how you can check if the checkbox is selected or not


foreach (DataGridViewRow row in dataGridView.Rows)
                {
                    //we check if the cell number 5(the checkbox) is checked or not 
                    if (Convert.ToBoolean(row.Cells[4].Value) == true)
                    {
                        //here you can do your save in database operation
                    }
                }





我个人讨厌直接使用datagrid数据。



我总是将我的数据保存在列表中,然后将数据放入数据网格中。



操作将更容易,并且产生错误的可能性很小。



如果您的类对象中没有已检查的属性,那么您可以设法使用inheritence添加neww属性(创建一个继承自您的新类)主要课程并为检查项目添加一个booleen道具)



希望它有所帮助



I personllay hate working with datagrid data directly.

I always save my data in a list and then put that data in the datagrid.

Operation will be much easier, and the possibilites to make error is minor.

If you don't have a checked properties in your class object, then you can manage to add a neww properties using inheritence(create a new class that inherit from your main class and add a booleen prop for checked items)

Hope it helps


嗨...

如何选择选中复选框时,将显示gridm的数值 [ ^ ]

谢谢你。
Hi...
how to select values frm gridview when checkbox is checked[^]
Thank u.


这篇关于如何在ASP.Net中使用CheckBox获取所选的GridView行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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