I'm new to VB.net/ASP. I'm using a Databound dropdown in ASP.net (VB). The dropdown l

Soldato
Joined
12 Dec 2006
Posts
5,904
I'm new to VB.net/ASP. I'm using a Databound dropdown in ASP.net (VB). The dropdown list is order in no sequence that I can fathom. How can I order it and and set the default. or better set the default as nothing so the user has to select something.
 
OspreyO said:
I'm new to VB.net/ASP. I'm using a Databound dropdown in ASP.net (VB). The dropdown list is order in no sequence that I can fathom. How can I order it and and set the default. or better set the default as nothing so the user has to select something.
I assume that the list is databound via a database, if so then to order your list Ascending or Descending go back into your query, and change the 'Sort Type'.

To add a default field set the AppendDataBoundItems property to 'True' in the DropDownList.
Then add a ListItem tag into your DropDownList e.g:

Code:
<asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Text="Text to be displayed in field" Value="Value of DropDownList" Selected="True" />
</asp:DropDownList>

Although one thing I do is set the Text property of the ListItem to 'Select from this list' or something similar.
Then to make the person select from the DropDownList, create a RequiredFieldValidator, link it to the DropDownList control and set the InitialValue to match the Text property in the ListItem.
Also set the AutoPostBack property of the DropDownList to 'True'.
Unless the person selects something other than the default value, the DropDownList will not be valid and won't postback.
 
Last edited:
Back
Top Bottom