[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I make an inserted item in my drop down list into 2nd position on the list?

Posted on 2011-04-26
5
Medium Priority
?
432 Views
Last Modified: 2012-05-11
I would like to make "**Manager Positions" 2nd on my list of my dynamic drop down list.  Currently, "--Select Position Title--" is in the first position, and "**Manager Positions" is in last position.

 
protected void SetValue2(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        if (filter != null)
        {
            ddl.Items.Insert(0, new ListItem("--Select Position Title--"));
            ddl.Items.Add(new ListItem("**Manager Positions"));
            if (filter.ContainsKey("Position_Title"))
            {
                foreach (ListItem li in ddl.Items)
                {
                    if (li.Text == filter["Position_Title"].ToString().Substring(2, filter["Position_Title"].ToString().Length - 3))
                    {
                        li.Selected = true;
                        return;
                    }
                }
            }
        }
    }
0
Comment
Question by:ocdc
  • 2
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
malikirfan28 earned 1600 total points
ID: 35469274
You can add it at second position by using following line.

ddl.Items.Insert(1, new ListItem("**Manager Positions"));
0
 
LVL 14

Assisted Solution

by:quizwedge
quizwedge earned 400 total points
ID: 35469278
ddl.Items.Insert(1, new ListItem("**Manager Positions"))

Open in new window

0
 
LVL 14

Assisted Solution

by:quizwedge
quizwedge earned 400 total points
ID: 35469290
Whoops, malikirfan28's comment wasn't there when I loaded the page and I forgot the semicolon.
0
 
LVL 4

Expert Comment

by:malikirfan28
ID: 35469333
But there is 1 minute difference between comments :).
0
 

Author Closing Comment

by:ocdc
ID: 35469407
Thanks guys.  I appreciate it.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question