hi

i have an drop down list in the web paage and it has Item A, Item B, Item C as items in the drop downlist. when i run the page how can i make it to display the Item B which is the 2nd item to be displayed in the drop down list box.

thanks
Anisha

Add the attribute, "selected=true" to the drop down list item.

This is how to set the selected index...

Me.drpDownList.SelectedIndex = 1

Which should select the second item in the list, just keep in mind, do this after the list is created not during creation as that will reset the selected index I believe.

Hope that helps,
Larry

Let me be more specific in the example I provided. Maybe i misunderstood the question.

Example..

<asp:DropDownList ID="dropDown1" runat="server" AutoPostBack="True">
  <asp:ListItem>Item A</asp:ListItem>
  <asp:ListItem Selected="True">Item B</asp:ListItem>
  <asp:ListItem>Item C</asp:ListItem>
</asp:DropDownList>

hi the above code works,
where to i write the code to get the vlue of the dropdownlost?

That would depend on when you need to access it, but it would be in the code behind page. You could reference it in the pageload if you need to use it then but you would probably want to surround it with a ispostback to make sure you are expecting it....

If IsPostBack then
    dim strValue as string = me.DropDown1.SelectedValue 'this gives you the value selected in the dropdown
End If 

Or you could do it in a button_click event as well....

dim strValue as string = me.DropDown1.SelectedValue 'this gives you the value selected in the dropdown

Hope that helps you,
Larry

thanks got it working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.