Link to home
Start Free TrialLog in
Avatar of JT_SIRO
JT_SIRO

asked on

How do I display unique items in Repeater?

I'm building a repeater, code listed below.  How do I only show unique items in the list?
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

No code posted ;)
Avatar of JT_SIRO
JT_SIRO

ASKER

oops
        foreach (DataRow row in dt.Rows)
        {
            intCountBadCategories = intCountBadCategories + 1;

            // Check to see if this is a valid category
            if (IsValidCategory(row["Category"].ToString()) == false)
            {
                // Add to Repeater
                DataRow newRow3 = dt3.NewRow();
                newRow3["Category"] = row["Category"].ToString();
                dt3.Rows.Add(newRow3);
            }
        }

Open in new window

If dt is populated from the database, the best place would be to use a SELECT DISTINCT in the code loading data into the datatable, dt.
otherwise, check if the value already exists in dt3. Something like:
if (IsValidCategory(row["Category"].ToString()) == false && dt3.Select("Category = '" + row["Category"].ToString().Replace("'","''") + "'").Length = 0)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial