0

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

3
Contributors
6
Replies
29
Views
4 Years
Discussion Span
Last Post by anisha.silva
0

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

1

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>
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.