Skip to content

Commit b89dc01

Browse files
authored
kb(dropdownlist):added kb for showing the default text only before an item is selected (#322)
1 parent 80b9cf5 commit b89dc01

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Show Default Text only before an item is selected
3+
description: How to modify the Default Text to be shown only before an item is selected
4+
type: how-to
5+
page_title: Show Default Text only before an item is selected
6+
slug: dropdown-kb-no-default-text-on-selection
7+
position:
8+
tags: telerik,blazor,dropdownlist,default,text
9+
ticketid: 1518898
10+
res_type: kb
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>DropDownList for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
24+
## Description
25+
26+
I want the DropDownList to show the default text only when no option is selected. E.g. once the user selects a value, they are not allowed to select 'null' again.
27+
28+
## Solution
29+
30+
You can modify the default text to be shown only before an item is selected by toggling the DefaultText parameter value depending on your business logic. The example below demonstrates how to achieve that.
31+
32+
````CSHTML
33+
@* Show the default text only when no option is selected *@
34+
35+
Selected value: @selectedValue
36+
<br />
37+
38+
<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="selectedValue"
39+
DefaultText="@( selectedValue == 0 ? "Please Select" : null )">
40+
</TelerikDropDownList>
41+
42+
@code {
43+
44+
int selectedValue { get; set; }
45+
46+
IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
47+
48+
public class MyDdlModel
49+
{
50+
public int MyValueField { get; set; }
51+
public string MyTextField { get; set; }
52+
}
53+
}
54+
````

0 commit comments

Comments
 (0)