Help with dropdownlist

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
 
N

nomad

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top