Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: ASP.NET FAQ


How do I Hide duplicate row values in a Gridview Control by Chance1234
Posted: 18 Jun 07

Say you have the following list of data

Country, Town, Sales
UK, London, 4322
UK, Leeds, 2342
UK, Salisbury, 1234
USA,New York, 1555
USA,Texas, 1112

On your Gridview, you want to show the data as

UK   London     4322
     Leeds      2342
     Salisbury  1234
USA  New York   1555
     Washington 1200
     Texas      1112

To hide the duplicate values (in this case country) use the following code on the RowDataBound event.


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

        if (e.Row.RowType == DataControlRowType.DataRow)
            //switch for first row
            if (e.Row.RowIndex == 1)
                GridViewRow Gprev = GridView1.Rows[e.Row.RowIndex - 1];
                if (Gprev.Cells[0].Text.Equals(e.Row.Cells[0].Text))
                    e.Row.Cells[0].Text = "";
            //now continue with the rest of the rows

            if (e.Row.RowIndex > 1)
                //set reference to the row index and the current value
                int intC = e.Row.RowIndex;
                string lookfor = e.Row.Cells[0].Text;

                //now loop back through checking previous entries for matches
                   GridViewRow Gprev = GridView1.Rows[intC-1];

                    if (Gprev.Cells[0].Text.Equals(e.Row.Cells[0].Text))
                            e.Row.Cells[0].Text = "";

                  intC = intC - 1;
                } while (intC >0);




Back to Microsoft: ASP.NET FAQ Index
Back to Microsoft: ASP.NET Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close