PagodNaUtak
asked on
DropDownList default value.
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.
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
ASKER
@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.
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.
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
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
ASKER
Hi, as posted in the ID:35068228, same reason with required field validator why I can't implement your suggestion.
regards,
Joseph
regards,
Joseph
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks! Perfect!
http://msdn.microsoft.com/en-us/library/aa479013.aspx
<asp:RequiredFieldValidato
runat="server" ErrorMessage="Please make a selection"
ControlToValidate="Metadat
InitialValue="Select A Value">
</asp:RequiredFieldValidat