如何找到缺少的ID号Gridview控件? [英] How to find missing ID Number Gridview control?
本文介绍了如何找到缺少的ID号Gridview控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格视图,如..
I have a grid view like..
sno Name ID
1 AAA 1
2 BBB 2
3 CCC 3
4 DDD 6
如果您观察到以上Gridview ..在此gridview中缺失4和5 ID号码..现在我想显示一条4,5 ID遗漏的提醒信息...
我该怎么办?
请帮助我
If you observe above Gridview..In this gridview missing 4 and 5 ID numbers..Now i want to shows an alert message like 4,5 ID are missing...
How can i do this?
Please help me
推荐答案
- 循环通过行。
- 在
列表
中存储ID
。 - 循环通过
列表
并比较当前和下一个Id
。如果差异大于1,则找到缺少的Id
并存储在另一个列表
中。 - 最后显示那些
ID
。
- Loop through the Rows.
- Store
Ids
in aList
. - Loop through the
List
and compare current and nextId
. If difference is greater than 1, then find missingId
and store in anotherList
. - At last show the those
Ids
.
1。获取第一行ID和最后一行ID。
2.创建可枚举范围
1. Fetch the First row id and last row id.
2. create Enumerable range
IEnumerable<int> nos= Enumerable.Range(firstrowid, lastrowid);
3.使用linq来丢失nos。
3. use linq to get missing nos.
var missingid = from a in nos
where !(from b in gvRows.AsEnumerable()
select b["id"])
.Contains(a)
select a;
这个问题经常出现,遗憾的是,最常见(也是最便携)的答案是创建一个临时表保留应该存在的ID,并进行左连接。 MySQL和SQL Server之间的语法非常相似。唯一真正的区别是临时表语法。
This question often comes up, and sadly, the most common (and most portable) answer is to create a temporary table to hold the IDs that should be there, and do a left join. The syntax is pretty similar between MySQL and SQL Server. The only real difference is the temporary tables syntax.
declare @id int
declare @maxid int
set @id = 1
select @maxid = max(id) from tbl
create table #IDSeq
(
id int
)
while @id < @maxid --whatever you max is
begin
insert into #IDSeq values(@id)
set @id = @id + 1
end
select
s.id
from
#idseq s
left join tbl t on
s.id = t.id
where t.id is null
drop table #IDSeq
这篇关于如何找到缺少的ID号Gridview控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文