How to insert distinct value in <select list item>
I have written a query to get result from table.
var queryres = (from r in objTestEntities.module_where r.PID ==id select r).ToList();
try
{
for (int j = 0; j < queryres.Count; j++)
{
string sModuleName = queryres[j].Title;
int iModuleId = queryres[j].ModuleID;
string sVersion = queryres[j].VersionNo;
sModuleNameList.Add(new SelectListItem
{
Text = sModuleName,
Value = iModuleId.ToString(),
Selected = true
});
sVersionList.Add(new SelectListItem
{
Text = sVersion,
Value = sVersion,
Selected = true
});
}
ViewData["Module"] = sModuleNameList;
ViewData["Version"] = sVersionList;
}
Now I want that sVersionList which is of type should have distinct value. But开发者_如何学运维 as from the queryres variable I am getting module name, and different module can have same version.
From above code in version list combo I am getting same version no multiple times.
But I want that one version should be seen only one time.
I have tried this also: ViewData["Version"] = sVersionList.Distinct(); But from this also I am not able to show the distict value in version list combo.
var moduleNameList = queryres.Select(o => new SelectListItem
{
Text = o.Title, Value = o.ModuleID.ToString(), Selected = true
});
var versionList = queryres
.Select(o => o.VersionNo)
.Distinct()
.Select(o => new SelectListItem
{
Text = o, Value = o, Selected = true
});
精彩评论