如何使用ASP.NET C#获取gridview中合并行的序列号 [英] How to get Serial number for merged rows in gridview using ASP.NET C#
本文介绍了如何使用ASP.NET C#获取gridview中合并行的序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码不适用于合并行。我想获取合并行的序列号。例如,有3个柱子C1(序列号),C2,C3。对于C2的一个值,存在多个C3值。因此我将C2合并为相同的值。但是我无法获得C2的序列号。
我使用下面的代码将C2合并为相同的值:
Hi ,
This code does not works for merged rows.I want to get the Serial number for Merged rows. For example there are 3 colums C1(seria no),C2,C3. For one value of C2 there is multiple values of C3. Therefore I have merged C2 for same values. But I am not able to get serial number for C2.
I am using below code for Merging the C2 for same values:
protected void GrdReportingDetails_PreRender(object sender, EventArgs e)
{
GridDecorator.MergeRows(GrdReportingDetails);
}
public class GridDecorator
{
public static void MergeRows(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];
for (int i = 1; i < row.Cells.Count; i++)
{
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}
}
}
}
推荐答案
您好,
我没有得到任何C#代码的问题。但如果数据来自SQL Stored Proc,我们可以在存储过程中使用一个内衬获得现成的序列号。
SELECT
dense_rank()OVER(ORDER BY R.Request_Id)为SrNo,
R.Request_Id,
R.Request_Type,
R. Client_Name,
R.Request_Rec_On,
R.Request_Due_On,
R.Success_Flag
来自REQ_Request R. br />
dense_rank()OVER(ORDER BY R.Request_Id)将解决查询,您可以在gridview中显示Stored proc输出。
Hi,
I didn't get any C# code for the issue. But if the data is coming from SQL Stored Proc, we can get the readymade serial number using a one liner in the stored proc.
SELECT
dense_rank() OVER (ORDER BY R.Request_Id) as SrNo,
R.Request_Id,
R.Request_Type,
R.Client_Name,
R.Request_Rec_On,
R.Request_Due_On,
R.Success_Flag
From REQ_Request R.
dense_rank() OVER (ORDER BY R.Request_Id) will solve the query and you may just display the Stored proc output in the gridview.
这篇关于如何使用ASP.NET C#获取gridview中合并行的序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文