locked
Not display a repeated value in Gridview column RRS feed

  • Question

  • User1769015664 posted

    My gridview display data as follows; how do I display 1, 2 and 3 only once the first time and blank for the next records? I used the following code but it removes the Type from every other row.

    Type     Value          Misc
    1         Course 1       aaa
    1         Course 2       bbb
    1         Course 3       ccc
    2         Course 4       ddd
    2         Course 5       eee
    2         Course 6       fff
    3         Course 7       ggg 

    string tempColumnValue = "";
    	foreach (GridViewRow row in GridView1.Rows)
    	{
    		if (string.Compare(row.Cells[0].Text, tempColumnValue, true) == 0)
    		{
    			row.Cells[0].Text = "";
    		}
    		else
    		{
    			tempColumnValue = row.Cells[0].Text;
    		}
    	}

    Monday, July 10, 2017 4:07 AM

Answers

  • User1769015664 posted

    For those who are interested in knowing the resolution:

    I modified my SQL query and used CTE to get this done.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 10, 2017 11:01 PM