Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to bind a list to DropDownList as Datasource. How can I do that..Below is my code
C#
DataTable dt = obj.FetchAllPerson();
List<string> ids = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
  ids.Add(dt.Rows[i][0].ToString());
}
DdlDelete.DataSource = ids;
DdlDelete.DataBind();


Thanks in Advance.
Posted
v2
Comments
What is the problem here?

 
Share this answer
 
Comments
Arup(Software engineer) 5-Sep-13 3:41am    
Thanks i show your advised link but here think i do the same and i am not getting the correct out put.
All i write in my code are Right. and it will give desired output.and my revised code is below.
C#
DataTable dt = obj.FetchAllPerson();
List<string> ids = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
   ids.Add(dt.Rows[i][0].ToString());
}
DdlDelete.DataSource = ids;
DdlDelete.DataBind();
ListItem item = new ListItem("-Select ID-", "0");
DdlDelete.Items.Insert(0, item);
 
Share this answer
 
v3

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