[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DropDownList default value.

Posted on 2011-03-08
6
Medium Priority
?
599 Views
Last Modified: 2012-05-11
Using Sharepoint 2007 and Visula Studio 2008(vb.net),

I have an item in the DropDownList 'Select A Value'. This item is the first and the default value for the dropdownlist. The code is shown below for reference.

However, When the dropdownlist is required, and the user does not select a value other than the item 'Select A Value'. I need the sharepoint to prompt that the dropdownlist is a required field.

How can I do that or any suggestions? If you have any other clarifications, please let me know.
Public Class MetadataDropdown
    Inherits DropDownList
    Implements IMetadataUserControl

     Public Property MetadataCategory() As String Implements IMetadataUserControl.MetadataCategory

    ''' <summary>
    ''' Constructor
    ''' </summary>
    ''' <param name="collection"></param>
    ''' <param name="selectedValues"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal collection As MetadataCollection, ByVal selectedValues As String)
        PopulateControl(collection, selectedValues)
        CreateDefaultListitem()
    End Sub

    ''' <summary>
    ''' Overloaded Constructor
    ''' </summary>
    ''' <param name="collection"></param>
    ''' <param name="selectedValues"></param>
    ''' <param name="defaultText"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal collection As MetadataCollection, ByVal selectedValues As String, ByVal defaultText As String)
        LoadValue(collection, selectedValues)
        CreateDefaultListitem()
    End Sub

    ''' <summary>
    ''' This method creates the "Select A Value" default value listitem 
    ''' then insert it in the dropdown.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub CreateDefaultListitem()
        'Create the listItem "Select A Value"
        Dim defaultListitem As New System.Web.UI.WebControls.ListItem
        defaultListitem.Text = "Select A Value"
        defaultListitem.Value = Nothing
        'Insert the default Listitem in the dropdown.
        Me.Items.Insert(0, defaultListitem)
    End Sub

End Class

Open in new window

0
Comment
Question by:PagodNaUtak
[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
6 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35068158
You can use a requiredfieldvalidator

http://msdn.microsoft.com/en-us/library/aa479013.aspx

<asp:RequiredFieldValidator id="RequiredFieldValidator1"  
  runat="server" ErrorMessage="Please make a selection"
  ControlToValidate="MetadataDropdown"
  InitialValue="Select A Value">
</asp:RequiredFieldValidator>
0
 
LVL 8

Author Comment

by:PagodNaUtak
ID: 35068228
@Dhaest, Thank you for your comment or suggestion.

but I could not implement your suggestion because it is a sharepoint page.
When you create a sharepoint page validation is automatically added.

I think the problem is that by default the selected item is the first item which is has the index of 0.
First item is the 'Select A Value'.

So, logically if the validation is checked there is actually a selected item. I just want to know that if there is a way in sharepoint that once the selected item in dropdownlist is 'Select A Value' or the SelectedIndex is 0, it will treat it as no selection or the selected index is -1.

Please, let me know if you need clarifications.

Again thank you for your suggestion.
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35068311
why don't you use the Range validation ?
giving a 0 as the default but setting the range validation from 1 till ....
That way the validation stays failing if the default is still selected

regards
poor beggar
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 8

Author Comment

by:PagodNaUtak
ID: 35068340
Hi, as posted in the ID:35068228, same reason with required field validator why I can't implement your suggestion.

regards,

Joseph
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 total points
ID: 35068919
Instead of giving the default item a value of 0 try an empty string ""
0
 
LVL 8

Author Closing Comment

by:PagodNaUtak
ID: 35079709
Thanks! Perfect!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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