Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all
I have a drop down list that I fill with data table by using function does that. After calling that function , I want to all item in the drop called (Other). I tried to make that but it failed to give me the result
select_city();             //the function that retrieve data
if (DT.Columns.Count > 0)
{
    drplst_City.DataSource = DT;
    drplst_City.DataTextField = "Name"
    drplst_City.DataValueField = "Id";
    drplst_City.Items.Add(new ListItem("other", ""));
    drplst_City.DataBind();
}


any help ,please?

thanks

[edit]inline code changed to code block, capitalizaion, removed spurious "i"s from teh word "Hi" - OriginalGriff[/edit]
Posted
Updated 13-Feb-11 22:26pm
v2

You are calling .DataBind() after you add your custom item, which will clear the control. change the order to:

C#
select_city(); //the function that retrieve data
if (DT.Columns.Count > 0)
{
drplst_City.DataSource = DT;
drplst_City.DataTextField = "Name"; drplst_City.DataValueField = "Id";
drplst_City.DataBind();
drplst_City.Items.Add(new ListItem("other", ""));
}
 
Share this answer
 
Comments
moon2011 14-Feb-11 4:33am    
thanks alot, it is working now
jim lahey 14-Feb-11 4:34am    
my pleasure
Hope this[^] may also give you an idea.
 
Share this answer
 
DropDownList ddl=new DropDownList()
ddl
 
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