Click here to Skip to main content
12,894,200 members (69,893 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 14 Sep 2011

Bind distinct list to Dropdown List from DataTable

, 15 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Bind distinct list to Dropdown List from DataTable
Sometimes, we need to bind distinct list from datatable retrieved from dropdown list from Datatable retrieved data from database:
DataView view = new DataView(table);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...);

table.DefaultView.ToTable(true, "Column1", "Column2" ...);

The sample code for this is as below:
DataTable dt = GetColors();
ddlColor.DataTextField = "ColorName";
ddlColor.DataValueField = "ColorID";
ddlColor.DataSource = dt.DefaultView.ToTable(true, "ColorID",  


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


About the Author

Software Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

Questionbind distinct values Pin
Manohar_manu2-Jun-14 23:38
groupManohar_manu2-Jun-14 23:38 
QuestionIts worked for me Pin
Manohar_manu2-Jun-14 23:37
groupManohar_manu2-Jun-14 23:37 
GeneralMy vote of 5 Pin
IronRed25-Sep-12 5:55
memberIronRed25-Sep-12 5:55 
GeneralMy vote of 1 Pin
d347hm4n5-Aug-12 22:59
memberd347hm4n5-Aug-12 22:59 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 15 Sep 2011
Article Copyright 2011 by AditSheth
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid