C# 如何在 RDLC 报告中为每个组添加行号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9770743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can add I rownumbers for each group on a RDLC Report?
提问by Mehmet
How can ? add row numbers like this:
怎么能 ?像这样添加行号:
GROUP 1
第 1 组
RowNumber ID Name Age
RowNumber ID 名称 年龄
1 231 test 43
2 324 test2 45
3 354 test3 34
GROUP 2
第 2 组
RowNumber ID Name Age
RowNumber ID 名称 年龄
1 657 test4 43
2 534 test5 45
3 678 test6 34
I want to do row numbers like this example.. For each group my row numbers will reset and start from 1 to groups row count.. My gruops(GROUP 1,GROUP 2, ....) are coming from db dynamically! How many group I have is not clear! hereis I found some solutions but I think those solutions are available for how many groups when we know!
我想做这个例子中的行号..对于每个组,我的行号将重置并从 1 开始到组行数.. 我的组(组 1,组 2,....) 动态来自数据库!我有多少组不清楚!这是我找到了一些解决方案,但我认为当我们知道时,这些解决方案可用于多少组!
采纳答案by David
RDLCs have a RowNumber("ScopeName")Function. This will return the row number of the record within the given scope.
RDLC 有一个RowNumber("ScopeName")功能。这将返回给定范围内记录的行号。
You can see the existing groups for the report below the designer under a "Row Groups" and "Column Groups" headers. Select the column inside the grouping where you want the row number and view the Row Columns, The default names will be:
您可以在设计器下方的“行组”和“列组”标题下看到报表的现有组。选择您想要行号的分组内的列并查看行列,默认名称为:
[(Group1)
≡(Details1)
Set the expression for the Row Number column to be
将行号列的表达式设置为
=RowNumber("Group1")
回答by Gin Uchiha
Right Click on your Report property then go to codethen paste the code below
右键单击您的报告属性,然后转到代码,然后粘贴下面的代码
Dim private count as integer = 0
Dim private iniRow as integer = 0
Dim private iniGrp as Object = ""
Public function MatrixRow(Byval rowNum as integer,Byval rowGrp as Object) as integer
if iniGrp = "" then
iniGrp = rowGrp
end if
if rowGrp <> iniGrp then
iniRow = 0
count = 0
iniGrp = rowGrp
end if
if iniRow = 0 then
iniRow = rowNum
end if
if rowNum = iniRow then
count = 0
end if
count = count + 1
Return count
End function
then use this function like
然后使用这个功能
=Code.MatrixRow(RowNumber(Nothing),(YourgroupfiledNameFromDataest))

