Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Nuts N Bolts of ASP.net

, 15 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
I would like to share a brilliant piece of code as a continuation to my Nuts N Bolts which I encounter on my day to day developments and maintenance here and there:This is for removing repeated data from DataTale: public DataTable FilterDuplicateRows(DataTable dTable, string colName) ...

I would like to share a brilliant piece of code as a continuation to my Nuts N Bolts which I encounter on my day to day developments and maintenance here and there:

This is for removing repeated data from DataTale:

 public DataTable FilterDuplicateRows(DataTable dTable, string colName) 
        {
            Hashtable hTable = new Hashtable();
            ArrayList duplicateList = new ArrayList();
            foreach (DataRow drow in dTable.Rows)
            {
                if (hTable.Contains(drow[colName]))
                    duplicateList.Add(drow);
                else
                    hTable.Add(drow[colName], string.Empty);
            }
            foreach (DataRow dRow in duplicateList)
                dTable.Rows.Remove(dRow);
            return dTable;
        }
Using the function:
private void BindGrid()
        {
            try
            {
                DataSet ds = (DataSet)ViewState["ds"];
                DataTable dt = (DataTable)ViewState["dt"];
                DataTable dtFiltered = new DataTable();               
                dtFiltered = FilterDuplicateRows(dt, "software");     
                gvRolePackage.DataSource = dtFiltered;                 
                gvRolePackage.DataBind();
             }
         }

License

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

Share

About the Author

Sanjay4India
Software Developer
India India
The Author holds degrees in Bachelor as well as Master of Computer Application. He firmly believes in the philosophy 'Sound Mind in Sound Body'. He loves Jogging, exersising and you may find him lost in deep thoughts when free.He feels Necessity is the mother of all logics and Programming can't be work but challenge whose output is fun n happiness.Bathroom is the place where he finds heaven.

Comments and Discussions

 
GeneralReason for my vote of 1 Brilliant? Why not filtering with a... Pinmembernmeteora22-Feb-11 3:41 
GeneralReason for my vote of 5 This is a great way to eliminate rep... PinmemberAnantharaman_N21-Feb-11 22:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.141029.1 | Last Updated 15 Feb 2011
Article Copyright 2011 by Sanjay4India
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid