Click here to Skip to main content
15,900,616 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i try below code for get selected item true bydefault for dropdownlist

clsMasterBizAction objBizAction = new clsMasterBizAction();
List<clsmastervo> objMSList = new List<clsmastervo>();
objMSList = objBizAction.getMasterDetails(strTableName, strAndQuery);
ddlcity.DataSource = objMSList;
ddlcity.DataTextField = "strValue";
ddlcity.DataValueField = "intID";
ddlcity.DataBind();


if (objMSList.Count > 0)
{
var result = (from m in objMSList
select m).Take(5);

List<string> selected = new List<string>();
foreach (var item in result)
{
selected.Add(item.strValue);
}

foreach (string row in selected)
{

ddlcity.Items.FindByText(row).Selected = true;

}

}

What I have tried:

i want to selected item true in dropdownlist with top 5 city by default
Posted
Updated 29-Jun-16 2:11am
Comments
ZurdoDev 29-Jun-16 8:10am    
What is your question? The error you posted in the title should be pretty clear, you can't select more than one item at a time.

1 solution

Hi,

check this...

Multi select Dropdown list in ASP.NET[^]

Hope this will help you.

Cheers
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-16 11:07am    
A 5.
—SA
Magic Wonder 30-Jun-16 1:42am    
Thanks

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