Link to home
Start Free TrialLog in
Avatar of learningnet
learningnet

asked on

how to set the default value in the dropdownlist control

I am trying to show the list of names in the dynamic drop down listbox, using the following code.

 <asp:DropDownList ID="lstLearnItName" runat="server" DataSourceID="dsLearnItNames"
                                    DataTextField="LearnItName" DataValueField="LearnItID">
                                   
                                     
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                         ErrorMessage="enter a Product ID" ControlToValidate="lstLearnItName"
                          SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>


<asp:SqlDataSource ID="dsLearnItNames" runat="server" ConnectionString="<%$ ConnectionStrings:sConnectionString %>"
                SelectCommand="SELECT * FROM [LearnItName]"></asp:SqlDataSource>


I just wanted to know how I can add a static listitem and set it to the default.

for an instance: <asp:ListItem Selected="true" Text="Please select" Value=""></asp:ListItem>

So that I can force the user to select an item before navigating to the next.

thanks in advance

regards
kay
ASKER CERTIFIED SOLUTION
Avatar of Binuth
Binuth
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of learningnet
learningnet

ASKER

guys,

its still not forcing me to select some other item from the drop down listbox

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                         ErrorMessage="please choose the name" ControlToValidate="lstLearnItName"
                          SetFocusOnError="True" Display="Dynamic" InitialValue="Please Select"></asp:RequiredFieldValidator>

please can you still advise
thanks