如何消除网格视图中前四列的重复数据? [英] How do I eliminate duplicate data for first four columns in grid view ?

查看:91
本文介绍了如何消除网格视图中前四列的重复数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格视图中有大约10列。我想从前四列中删除重复数据。所有这四列中的数据可以相同。但是应该逐列消除数据。不应将第一列与其他列进行比较。

对于Ex:我有类似的数据



I have approx 10 columns in grid view. I want to eliminate duplicate data from first four columns. Data can be same in all these four columns. But data should be eliminated column wise. First column should not be compared to other ones.
For Ex: i have data like

PNAME	DNAME	SNUMBER	VALUE	field_name	operation	old_value new_value
906	906	906	CH1	AdjPeriod	Delete	6/13/2018 5:39:26 PM	1
906	906	906	CH1	CollectPayment	Delete	False	1
906	906	906	CH1	Current_Liability_Bal	Delete		
906	906	906	CH1	Current_ROU_Bal	Delete		1
906	906	906	CH1	FASB_Adj_Balance	Delete		
90906	89906	789906	CH1	FASB_Amount	Delete	76.92	
90906	89906	789906	CH1	FASB_Classification	Delete	5	
90906	89906	789906	CH1	FASB_End_Date	Delete	12/31/2010 12:00:00 AM	1
90906	89906	1906	CH1	FASB_Balance	Delete		
90906	89906	1906	CH1	FASB_Periods	Delete	13	
90906	89906	1906	CH1	FASBR_ID	Delete	16033	1
90906	89906	1906	CH1	Fixed_Monthly_Index_Rent	Delete

和预期结果如下:



and expected result is like:

PNAME	DNAME	SNUMBER	VALUE	field_name	operation	old_value new_value
906	906	906	CH1	AdjPeriod	Delete	6/13/2018 5:39:26 PM	1
				CollectPayment	Delete	False	1
				Current_Liability_Bal	Delete		
				Current_ROU_Bal	Delete		1
				FASB_Adj_Balance	Delete		
90906	89906	789906	CH1	FASB_Amount	Delete	76.92	
				FASB_Classification	Delete	5	
				FASB_End_Date	Delete	12/31/2010 12:00:00 AM	1
		1906	CH1	FASB_Balance	Delete		
				FASB_Periods	Delete	13	
				FASBR_ID	Delete	16033	1
				Fixed_Monthly_Index_Rent	Delete





我尝试了什么:



我在下面的代码中尝试了这个,但这是仅适用于第一列。





What I have tried:

I have tried this below code, but this is working fine only for first column.

string initialnamevalue = "";
        if (gv.Rows.Count > 0)
        {
            initialnamevalue = gv.Rows[0].Cells[0].Text;
        }

        //Step 2:

        for (int i = 1; i < gv.Rows.Count; i++)
        {
            if (gv.Rows[i].Cells[0].Text == initialnamevalue)
            gv.Rows[i].Cells[0].Text = string.Empty;
            else
                initialnamevalue = gv.Rows[i].Cells[0].Text;
        }

推荐答案

Quote:



我已尝试过以下代码,但这只适用于第一列。


I have tried this below code, but this is working fine only for first column.





所以,使用第二,第三和第四列的逻辑相同。例如(两列版本):



So, use the same logic for second, third and fourth column. For example (two columns version):

string sCol1Value = string.Empty;
string sCol2Value = string.Empty;
sCol1Value = gv.Rows[0].Cells[0].Text;
sCol2Value = gv.Rows[0].Cells[1].Text;
//Step 2:
for (int i = 1; i < gv.Rows.Count; i++)
{
    if (gv.Rows[i].Cells[0].Text == sCol1Value)
        gv.Rows[i].Cells[0].Text = string.Empty;
    else
        sCol1Value = gv.Rows[i].Cells[0].Text;
            
    if (gv.Rows[i].Cells[1].Text == sCol2Value)
        gv.Rows[i].Cells[1].Text = string.Empty;
   else
        sCol2Value = gv.Rows[i].Cells[1].Text;
}





知道了吗?



Got it?


这篇关于如何消除网格视图中前四列的重复数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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