Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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;
        }
Posted
Updated 27-Jun-18 22:25pm
v3

1 solution

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):
C#
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?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900