KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Lets say I have a list of some column values coming from a table, how do I remove empty strings and duplicate values. Please see the following code: List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList(); This is what I have coded just now but but Amiram's code is way more elegant, so I will choose that answer here is how I did it: DataTable dtReportsList = someclass.GetReportsList(); if (dtReportsList.Rows.Count > 0) { List<string> dtList = dtReportsList.AsEnumerable().Select(dr => dr.Field<string>("column1")).ToList(); dtList.RemoveAll(x=>x == ""); dtList = dtList.Distinct().ToList(); rcboModule.DataSource = dtList; rcboModule.DataBind(); rcboModule.Items.Insert(0, new RadComboBoxItem("All", "All")); }
Tags (comma-separated)
Save Edits
Cancel