Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a new value to the drop down list box

I have a drop down list box which has one of the values to be others. I want to move these value to the last. Please help me with this. The code i am using is as follows

ddlAssetsCountryOthersone.DataSource = lstIMAssetsByCountryOthers;
ddlAssetsCountryOthersone.DataTextField = "AssetDescription";
ddlAssetsCountryOthersone.DataValueField = "AssetDescription";
ddlAssetsCountryOthersone.DataBind();
ddlAssetsCountryOthersone.Items.Remove(
             ddlAssetsCountryOthersone.Items.FindByValue(
                Constants.PhilosophyAndEmphasis.Other.ToString()));

How can i add the others back to the drop down list in the last

like image 807
Sumeru Suresh Avatar asked Sep 16 '25 19:09

Sumeru Suresh


1 Answers

try this after your databind :

ddlAssetsCountryOthersone.Items.Add(new ListItem("Others", "Others"));

By the way if you use Insert method, you can insert the item you want to the position you want. For example the code below adds the Other option to the 4th order :

ddlAssetsCountryOthersone.Items.Insert(4, new ListItem("Others", "Others"));
like image 103
Canavar Avatar answered Sep 19 '25 09:09

Canavar