Mysimple World
Mysimple World

Reputation: 93

select default value in dropdown

how to select default value in dropdown here is the dropdown

<asp:DropDownList ID="DropDownList4" runat="server" EnableViewState="true" 
    class="vpb_dropdown" DataTextField="ApproveType" DataValueField="ApproveID"
        AutoPostBack="true" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
                         <asp:ListItem Text="Pending"  Value="3"></asp:ListItem>
                         <asp:ListItem Text="Approve" Value="1"></asp:ListItem>
                         <asp:ListItem Text="Reject" Value="2"></asp:ListItem>
                    </asp:DropDownList>

i want to select pending as default..

Upvotes: 3

Views: 70870

Answers (5)

PJM
PJM

Reputation: 550

Above answer is correct you can do it in the mark up as noted above by including:

SelectedValue= "3"

            <asp:DropDownList ID="DropDownList4" runat="server" EnableViewState="true"      class="vpb_dropdown" DataTextField="ApproveType" SelectedValue= "3" DataValueField="ApproveID"         AutoPostBack="true" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">

http://msdn.microsoft.com/en-us/library/0dzka5sf(v=vs.85).aspx

Upvotes: 3

briskovich
briskovich

Reputation: 690

Put this in your page_load event

DropDownList4.SelectedIndex = 0 ; 

This will set your drop down to the first item on the list.

Upvotes: 3

knguyen
knguyen

Reputation: 76

You can get the value representing for pending first, let say PedingValue. Then:

DropDownList4.SelectedValue = PendingValue;

in the Page_load event.

Upvotes: 2

MikeSmithDev
MikeSmithDev

Reputation: 15797

If you don't want to do it from the code behind, you can do it using Selected:

<asp:ListItem Text="Pending" Selected="true" Value="3"></asp:ListItem>

MSDN: ListItem Class

Upvotes: 7

tymeJV
tymeJV

Reputation: 104775

How about:

DropDownList4.SelectedValue = 3

Or set the value to 0 to make it default with no code.

Upvotes: 10

Related Questions