删除GridView中的行 [英] deleting rows in the gridview

查看:71
本文介绍了删除GridView中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类似
的字典

I''ve created a Dictionary like

Dictionary<department,bool> dict= new Dictionary<department,bool>();



这里Department是一个类,我有Department的部门编号,名称和代码".然后在"bool"中发送此人是否为"HOD"的信息.

正在将记录添加到该词典中,例如



here Department is a class and I have `DepartmentId,Name and Code` for the departments. And in the `bool` am sending whether the person is `HOD` or not.

Am adding the records to this Dictionary like

dict.Add(department,chkHOD.checked);



在这里,记录已成功添加到Dictionary,然后将Dictionary绑定到GridView,如



here the records are successfully added to the Dictionary and after this am binding the Dictionary to a GridView like

gridDept.Datasource=dict;
  gridDept.Databind();



现在,插入的记录在gridview中显示良好.之后,将这些记录存储在数据库的"StaffDepartments"表中.我在员工部门"表中有3列



now the inserted records are displayed fine in the gridview. After this am storing this records in the ''StaffDepartments'' table in my database. I have 3 columns in the ''Staffdepartments'' table

1.StaffId(PK - has link with the Staff table)<br />
 2.DepartmentId(PK - has link with the Department table)<br />
 3.IsHOD.



在这里,记录可以很好地存储在数据库中.将记录添加到数据库中没有问题.

我在这里有问题

**** 1.如何在添加到词典之前检查DepartmentId是否已存在.
2,编辑人员详细信息时,如何通过选中Gridview行中的复选框从词典中删除选定部门(此处的记录来自数据库,因此当我单击删除按钮时,应在数据库中删除记录还有)****

如果它是列表而不是字典,我可以通过
获取DepartmentId



here the records are stored fine in the database.No problem in adding the records into the database.

I have some questions here

****1.How can check whether the DepartmentId is already there in the Dictionary before adding to it.
2.When am editing the staff detail how can I delete the Selected Department from the Dictionary by checking the checkbox in Gridview rows.(here the records are coming from the database, so when I click delete button the records should be deleted in the database as well)****

if its a List instead of Dictionary, I can get the DepartmentId by

int departmentId = (int)gridDept.DataKeys[row.RowIndex].Values["DepartmentId"];



但是在字典中,我不知道如何对键和值对做同样的操作..任何人都可以在这里帮助我.



but in Dictionary i dunno how to do the same with Key and Value pairs....can anyone help me here.

推荐答案



您需要做的是使用LINQ查询字典

Hi,

What you will need to do is to query your dictionary using LINQ

List<dict> mylist = new List<dict>
mylist = dict.where(x=>x.value.deptID=yourdepID).tolist();
if(mylist.count>0)
{
// value exists
// to update you will need to create a new entry
// delete the old one
// insert the new value
}
else
{
//insert new
}</dict></dict>



语法可能不是100%正确,因为我目前无法测试.

希望对您有帮助.



The syntax may not be 100% correct as I cannot test at the moment.

Hope this helps you.


这篇关于删除GridView中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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