Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set the default value in the dropdownlist control

Posted on 2008-10-09
3
Medium Priority
?
828 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:learningnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
Binuth earned 1400 total points
ID: 22677532
better to change your sql query than static listitem
like...

SELECT -1 AS LearnItID,"Please select" AS LearnItName UNION SELECT LearnItID,LearnItName FROM [LearnItName]
SELECT -1 AS LearnItID,"Please select" AS LearnItName UNION SELECT LearnItID,LearnItName FROM [LearnItName]

Open in new window

0
 
LVL 32

Assisted Solution

by:Daniel Wilson
Daniel Wilson earned 600 total points
ID: 22677533
<asp:SqlDataSource ID="dsLearnItNames" runat="server" ConnectionString="<%$ ConnectionStrings:sConnectionString %>"
                SelectCommand="SELECT 0 as LearnItID, 'Please Select' as LearnItName UNION SELECT LearnItID, LearnItName FROM [LearnItName]"></asp:SqlDataSource>
0
 

Author Comment

by:learningnet
ID: 22678005
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question