473,491 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with dropdownlist

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
Aug 11 '08 #1
2 1103
"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

Aug 11 '08 #2
On Aug 11, 10:37*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"nomad" <d.bedg...@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 MVPhttp://www.markrae.net
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.
Aug 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2755
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
1961
by: Frank Rocco | last post by:
Hello, I have a DropDownList that I populate from an odbc datasource in code. When I bring up the form for editing, how do I select the value in the DropDownList based on a value stored in the...
1
1699
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one...
10
10706
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
0
1812
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
0
2384
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
0
1455
by: ana_gil | last post by:
hello i have a problem with a dropdown list i am populating from an Access table. I´ve seen this problem in other discussions but i can´t seem to find the solution. please help. my .aspx has...
2
1545
by: rocksoft | last post by:
Hi I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist in my application to populate the data from mysql database, i have got problem while...
1
4905
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
4
8532
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.