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();
}
}
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. For a cloud application demo please do visit
https://www.youtube.com/watch?v=klGX6U0uURI