# Using DropDownList field for making another property required or not required

## Environment

<table>
	<tbody>
		<tr>
			<td>Product Version</td>
			<td>2022.3.913</td>
		</tr>
		<tr>
			<td>Product</td>
			<td>Telerik UI for ASP.NET Core Grid</td>
		</tr>
	</tbody>
</table>

## Description

How to dynamically change if a field is required in PopUp Edit Mode of a Telerik UI for ASP.NET Core Grid by using another field with DropDownList Editor?

## Solution

The example below is implemented as per the following steps:

1. Use a DataAnnotation attribute for the DropDownList to point to the desired Editor Template for the field.
2. Handle the [`Change`](https://docs.telerik.com/kendo-ui/api/ui/dropdownlist/events/change) Event of the DropDownList.
3. In the Event handler, get the input field that will be set as required or non-required, depending on the value of the DropDownList.
4. Use jQuery to set the required property to true or false.

The following example demonstrates the steps described above.

```Razor TestEditor.cshtml
@model string

@(Html.Kendo().DropDownList()
          .Name("EnableShipName")
          .BindTo(new List<string>() {
              "ShipName is required",
              "ShipName is not required"
          })
         .HtmlAttributes(new { style = "width: 100%" })
         .Events(e => e.Change("onDDLChange"))
        )
```

```C# Model
        [UIHint("TestEditor")]
        public string EnableShipName { get; set; }
```

```JavaScript
   function onDDLChange() {
        var dropDownList = this;
        var ddlValue = dropDownList.value();

        if (ddlValue == "ShipName is required") {
            $("#ShipName").prop('required', true);
        }
        else {
            $("#ShipName").prop('required', false);
        }
    }
```

The editable Grid initializes the Kendo Validator internally. It uses the input's `required` attribute for built-in validation, so no separate Validator initialization is needed.

To verify the behavior:

1. Edit a data item in the Grid popup.
2. Set the DropDownList value to `ShipName is required`.
3. Clear the `ShipName` field and blur it. The Grid displays a validation message and prevents saving.
4. Set the DropDownList value to `ShipName is not required`. The `ShipName` field is no longer required.

For more examples on Grid editing, see the following demos:

* [Grid Popup Editing](https://demos.telerik.com/aspnet-core/grid/editing-popup)
* [Grid Editing Custom Editor](https://demos.telerik.com/aspnet-core/grid/editing-custom)

## More ASP.NET Core Grid Resources

* [ASP.NET Core Grid Documentation](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET Core Grid Demos](https://demos.telerik.com/aspnet-core/grid/index)

* [ASP.NET Core DataGrid Product Page](https://www.telerik.com/aspnet-core-ui/grid)

* [Telerik UI for ASP.NET Core Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-core-ui/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET Core Forums](https://www.telerik.com/forums/aspnet-core-ui)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET Core](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET Core](https://docs.telerik.com/aspnet-core/api/grid)
* [Telerik UI for ASP.NET Core Breaking Changes](https://www.telerik.com/aspnet-core-ui/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET Core Knowledge Base](https://docs.telerik.com/aspnet-core/knowledge-base)
