How to select an item in a DropDownList by value Asp.Net

Created: 31/10/2013 07:56:09 p.m.

How to select an item in a DropDownList by value Asp.Net

Software: Visual Studio 2012, fwk 3.5

Code i used.

    <form id="form1" runat="server">
        <asp:DropDownList ID="ddListTest" runat="server">
            <asp:ListItem Value="item1" Selected="True">Item 1</asp:ListItem>
            <asp:ListItem Value="item2">Item 2</asp:ListItem>
            <asp:ListItem Value="item3">Item 3</asp:ListItem>


public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        ddListTest.Items.FindByValue("item2").Selected = true;

1) Add dropdownlist to your website
and in code-behind try to select some item by using FindByValue

This is a result:

2) But what about if i whant to set previously selection of any item in html like this example:

I will recive: You cant select more than one item.

To solve this issue just add ClearSelection before your assignment like this:

And the result

That's all, hope this helps somebody.


User: Bhuva Bhavesh Comment date: 21/05/2014 01:24:36 a.m.
very useful
User: sadegh Comment date: 05/10/2014 03:29:23 a.m.
Tanks - its very help me in one Problem
User: fery Comment date: 04/02/2015 10:29:05 a.m.
 this help for me . thx a lot
User: lina Comment date: 25/02/2015 04:09:52 a.m.
please send us the code for sending mail in c#)
User: Docstorus Comment date: 25/02/2015 06:20:02 p.m.
you meen this one?
User: FRIXER Comment date: 23/09/2019 07:27:25 p.m.
muchas gracias, era justo lo que andaba buscando, saludos buen hombre =)
User: Docstorus Comment date: 25/09/2019 10:06:41 p.m.
Gracias @FRIXER !

Go to Comments