Help with dropdownlist

  • Thread starter Thread starter nomad
  • Start date Start date
N

nomad

Hi,

I have a databound dropdownlist. I have added
AppendDataBoundItems="True" so that I am able to enter a item in the
dorpdownlist of "-- Please select --". I would like to be able to set
it so that this value isn't selectable because as it stands if they
select that value then my applicaiton will fall over.

Appreciate any help on this.

Thanks
 
Your application will not fall over if you write it properly.

Specifically, in this case, you need to start using validation on your
postbacks.

If it's not valid for a user to submit the form without selecting one of
"real" databound items in the DropDownList, then don't allow them to do
that.

E.g.

<script type="text/javascript">
    function validateForm()
    {
        var myDropDownList =
document.getElementById('<%=MyDropDownList.ClientID%>');
        if (myDropDownList.selectedIndex < 1)
        {
            alert ('Please select an option');
            myDropDownlList.focus();
            return false;
        }
    }
</script>

<asp:Button ID="MySubmitButton" runat="server" Text="Submit"
OnClick="MySubmitButton_Click" OnClientClick = "return validateForm();" />

Hi Mark,

Thanks for the reply. I thought there may have been a setting which
allows you to set the first item as unselectable, without writing a
method to catch this.
 
Back
Top