"nomad" <d.*******@o2.co.ukwrote in message
news:a7**********************************@p25g2000 hsf.googlegroups.com...
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.
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.ClientI D%>');
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();" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net