# Clear the value (selection) of a combobox, dropdown, input

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>
                AutoComplete for Blazor,<br />
                ComboBox for Blazor<br />
                DatePicker for Blazor<br />
                DateTimePicker for Blazor<br />
                DropDownList for Blazor<br />
                NumericTextBox for Blazor,<br />
                TextBox for Blazor,<br />
                TimePicker for Blazor
            </td>
        </tr>
    </tbody>
</table>

## Description

There is no Clear() method equivalent for combo boxes. How do I clear the selection or value of the input without changing it to the placeholder text value?

## Solution

In Blazor, you clear the value of an input (such as a combobox, textbox, doropdownlist, date picker and so on) by changing its `Value` parameter to the `default` value for its type (or to a desired other value).

With the MVVM patter used by the framework, you do not need methods like `Clear()` to remove selection - when the `Value` matches the default value for its type, the Telerik component will show the placeholder automatically (if one is set).

> tip This approach applies to all inputs

Here are a few examples in their corresponding tabs per component:

> caption Clear an input (or selected item in a dropdown/combobox)

```RAZOR.skip-repl ComboBox
@selectedValue

<br />
<TelerikButton OnClick="@Clear">Clear</TelerikButton>

<TelerikComboBox @bind-Value="selectedValue" Placeholder="Select something"
                 Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField">
</TelerikComboBox>

@code {
    int selectedValue { get; set; }
    void Clear()
    {
        // clear the combo box value (selection)
        selectedValue = default;
    }

    //data binding below
    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
    }

    //Define a preselected value when the component initializes
    protected override void OnInitialized()
    {
        selectedValue = 3;
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
}
```

```RAZOR Textbox
@selectedValue

<br />
<TelerikButton OnClick="@Clear">Clear</TelerikButton>

<TelerikTextBox @bind-Value="@selectedValue" PlaceHolder="type something"></TelerikTextBox>
@code{
    string selectedValue { get; set; } = "lorem ipsum";
    void Clear()
    {
        selectedValue = null;
    }
}
```

```RAZOR DropDownList
@selectedValue

<br />
<TelerikButton OnClick="@Clear">Clear</TelerikButton>

<TelerikDropDownList @bind-Value="selectedValue" DefaultText="Select something"
                 Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField">
</TelerikDropDownList>

@code {
    int selectedValue { get; set; }
    void Clear()
    {
        selectedValue = default;
    }

    //data binding below
    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
    }

    //Define a preselected value when the component initializes
    protected override void OnInitialized()
    {
        selectedValue = 3;
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
}
```

```RAZOR DatePicker
@selectedValue

<br />
<TelerikButton OnClick="@Clear">Clear</TelerikButton>

<TelerikDatePicker @bind-Value="@selectedValue"></TelerikDatePicker>

@code {
    DateTime? selectedValue { get; set; } = DateTime.Now.Date;
    void Clear()
    {
        selectedValue = default;
    }
}
```

```RAZOR NumericTextbox
@selectedValue

<br />
<TelerikButton OnClick="@Clear">Clear</TelerikButton>

<TelerikNumericTextBox @bind-Value="@selectedValue"></TelerikNumericTextBox>

@code {
    int? selectedValue { get; set; } = 123;
    void Clear()
    {
        selectedValue = default;
    }
}
```

## See Also

* [The basics of value binding and data binding](https://www.telerik.com/blazor-ui/documentation/common-features/data-binding/overview#data-binding-vs-value-binding)
