如何在Crystal Report C#中添加行号 [英] How to add row numbering in crystal report C#
本文介绍了如何在Crystal Report C#中添加行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开始使用 crystal报表
创建报表。我可以使用数据集
和 sql
来显示所有内容,除了自动行编号
。
I have started creating reports using crystal reports
. I am able to show everything using dataset
and sql
except for the auto-row numbering
.
这是我的代码:
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=Kim; initial catalog=DBO;user id=sa; password=passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select Name as DataColumn1, Age as DataColumn2, from tbl1";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
cnn.Close();
DataSet2 ds = new DataSet2();
dscmd.Fill(ds, "DataTable2");
CrystalReport1 objRpt = new CrystalReport1 ();
objRpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = objRpt;
CrystalReportViewer1.RefreshReport();
报告结果如下:
No Name Age
Kim 22
Ian 29
Aris 27
需要显示以下报告:
No Name Age
1 Kim 22
2 Ian 29
3 Aris 27
你能给吗我对如何添加行号的想法。
Can you give me idea on how to add row number.
推荐答案
- 创建新的运行总计字段
- 为字段命名,例如 RowNo
- 选择要汇总的字段
- 设置摘要类型到区别计数
- 在评估中,选择对于每条记录
-
在重置中,选择永远不会
- Create a new 'Running Total Field'
- Give a name for the field Like 'RowNo'
- Choose a field to summarize
- Set the 'Type of summary' to 'distinct count'
- In 'Evaluate' choose 'For each record'
In 'Reset' choose 'Never'
单击确定
将字段添加到报告中。
Click OK Add the field to the report.
这篇关于如何在Crystal Report C#中添加行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文