Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a combo box with list of data.
i want to display the distinct value of data in ComboBox and with value member.

Below is my code:

List<templateentity> objTemp = null;
objTemp = (List<templateentity>)note.Body;
cmbDataset.DataSource = objTemp;
cmbDataset.DisplayMember = "DatasetName";
cmbDataset.ValueMember = "DatasetID";
Posted

You can do this, (you may have to tweak it a bit to complie and work for you)
C#
ddlName.DataSource = items.Select(item=>item.Name).Distinct().ToList();
ddlName.DataBind();

ddlSize.DataSource = items.Select(item=>item.Size).Distinct().ToList();
ddlSize.DataBind();

ddlPrice.DataSource = items.Select(item=>item.Price).Distinct().ToList();
ddlPrice.DataBind();

And then find the itemID based on the selection of all three dropdown lists.

This is C# and assumes that you have LINQ

Hope this helps.

Edit-- (if no LINQ)
C#
IList<string> names = new List<string>();

foreach (Item item in Items)
    if (!names.Contains(item.Name))
        names.Add(name);

ddlName.DataSource = names;
ddlName.DataBind();
</string></string>

//Do similar for price and size.

Edit (use SQL commands)
SQL
select distinct Name from Item
select distinct Size from Item
select distinct Price from Item
 
Share this answer
 
var filterData = objTemp.Select(x => new { DatasetID = x.DatasetID, DatasetName = x.DatasetName }).Distinct();
cmbdataset.DataSource = filterData.ToList()
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900