在另一个网格中选中的复选框上的gridview绑定 [英] gridview binding on checkbox checked in another grid

查看:79
本文介绍了在另一个网格中选中的复选框上的gridview绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个网格视图,此网格视图的每一行都包含一个复选框,当我选中该复选框时,相关的行将被绑定到另一个网格中,我希望如果所选记录已经存在于第二个网格中,则这些行不应添加到第二个网格中.
以简洁的方式,我要防止选择已经存在的记录.

等待您的意见,请为我提供代码.


谢谢

Hi Everybody

i have a grid view ,this grid view contains check box at each row ,when i am checking the check box then related row is being bind into another grid,i want that if selected record is already existing into the second grid then the those row should not be added into the second grid.
in concise way i want to prevent the selection of already existing record .

waiting for your view ,provide me code if possible.


thanks

推荐答案

以简洁的方式,我想防止选择已经存在的记录.
在将第一个网格选择的数据行添加为要与grid2绑定的数据表行之一之前(可能是复选框单击事件),您需要遍历新的数据表并查看记录是否已存在-如果存在,请跳过添加. br/>
因此,第二个网格数据源表上会有一个foreach循环.循环并匹配已存在的唯一rowid与当前所选项目的rowid.如果找到匹配项,则中断循环并返回.如果整个foreach循环结束后都找不到匹配项,则将新记录添加到表中.试试吧!

如果在ASP.NET中进行此操作,则可以在客户端保留选定记录ID的副本,并处理Javascript中的复选框.
in concise way i want to prevent the selection of already existing record .
Before adding first grid selected datarow as one of the rows of datatable to be bind with grid2 (probably it would be check box clicked event), you need to loop through new datatable and see if record already exists - If so, skip adding.

Thus, there would be a foreach loop on second grid datasource table. loop and match the unique rowid that already exists with the rowid of current selected item. If you find a match break the loop and return. If you dont find a match after whole foreach loop comes to an end, add the new record to table. Try!

If you were doing this in ASP.NET, you could have kept a copy of selected record id''s on client side and handled the checkbox in Javascript.


private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = e.RowIndex;

            if ((bool)dataGridView2.Rows[index].Cells[0].Value == true)
            {
                //The data is true
                //Cells[0] is the checkbox control
                //dataGridView2.Rows[index].Cells[0].Value returns an object so you must cast it to a boll using (bool)
            }
        }


这篇关于在另一个网格中选中的复选框上的gridview绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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