---
title: "If statement on dropDownList listItem"  
description: "If statement on dropDownList listItem"  
author: "Anonymous User"  
published: 2014-11-20  
updated: 2014-11-20  
canonical: https://www.mindstick.com/forum/12666/if-statement-on-dropdownlist-listitem  
category: "asp.net"  
tags: ["asp.net", "dropdown"]  
reading_time: 1 minute  

---

# If statement on dropDownList listItem

I need to add a [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) to a [DropDownList](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework) where a method can be executed by [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click) only if the user has selected a value different than the [listItem](https://www.mindstick.com/forum/23267/insert-a-listitem-to-a-dropdownlist) ([default value](https://www.mindstick.com/forum/2035/default-value-when-using-singleordefault)).

```
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"    
DataSourceID="SqlDataSource5" DataTextField="proj_name"
DataValueField="proj_name">       
<asp:ListItem Text="Select a project to clone" Value="" /></asp:DropDownList>
```

How can I [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) an if condition to [validate](https://www.mindstick.com/forum/1490/what-is-better-solution-for-validate-form-textboxs-value) that the [selected value](https://www.mindstick.com/forum/525/get-selected-value-of-datagridviewcomboboxcolumn) is not the ListItem (default value)?

## Replies

### Reply by Sumit Kesarwani

You can use asp.net delivered validation controls

```
<asp:RequiredFieldValidator id="rfv1"  ControlToValidate="DropDownList1"   Display="Static"                   
ErrorMessage="* Select a value"   InitialValue="DefaultValueHere"     runat="server"                   
ValidationGroup="V1"/>
```

Then edit your [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) markup to use ValidationGroup

<asp:Button Id="button1" ValidationGroup="V1" .../>

In your codebehind button click code add this

```
protected void button1_onlick(Object sender, EventArgs e){     If(Page.IsValid)     {       // your existing code here     }}
```


---

Original Source: https://www.mindstick.com/forum/12666/if-statement-on-dropdownlist-listitem

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
