@@ -220,7 +220,13 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
220220```` RAZOR
221221@using Telerik.DataSource.Extensions
222222
223- <TelerikDropDownList @ref="@TheDropDown"
223+ <TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
224+ OnClick="@RebindComponents">Rebind Components</TelerikButton>
225+
226+ <br />
227+ <br />
228+
229+ <TelerikDropDownList @ref="@DropDownListRef"
224230 TItem="@SampleModel"
225231 TValue="@int"
226232 OnRead="@OnDropDownRead"
@@ -236,13 +242,10 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
236242 </ItemTemplate>
237243</TelerikDropDownList>
238244
239- <TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
240- OnClick="@RebindComponents">Rebind Components</TelerikButton>
241-
242245<br />
243246<br />
244247
245- <TelerikGrid @ref="@TheGrid "
248+ <TelerikGrid @ref="@GridRef "
246249 TItem="@SampleModel"
247250 OnRead="@OnGridRead"
248251 AutoGenerateColumns="true"
@@ -251,34 +254,34 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
251254 PageSize="5" />
252255
253256@code {
254- TelerikGrid<SampleModel> TheGrid { get; set; }
255- TelerikDropDownList<SampleModel, int> TheDropDown { get; set; }
257+ private TelerikGrid<SampleModel>? GridRef { get; set; }
258+ private TelerikDropDownList<SampleModel, int>? DropDownListRef { get; set; }
256259
257- List<SampleModel> GridData { get; set; }
258- List<SampleModel> DropDownData { get; set; }
260+ private List<SampleModel> GridData { get; set; } = new();
261+ private List<SampleModel> DropDownData { get; set; } = new();
259262
260- int DropDownValue { get; set; } = 1;
263+ private int DropDownValue { get; set; } = 1;
261264
262- int ItemCounter { get; set; } = 3;
265+ private int ItemCounter { get; set; } = 3;
263266
264- void RebindComponents()
267+ private void RebindComponents()
265268 {
266- GenerateData(); // simulate change in the data
269+ GenerateData(); // simulate data change
267270
268- TheGrid .Rebind();
269- TheDropDown .Rebind();
271+ GridRef? .Rebind();
272+ DropDownListRef? .Rebind();
270273 }
271274
272- async Task OnGridRead(GridReadEventArgs args)
275+ private async Task OnGridRead(GridReadEventArgs args)
273276 {
274- var result = GridData.ToDataSourceResult (args.Request);
277+ var result = await GridData.ToDataSourceResultAsync (args.Request);
275278 args.Data = result.Data;
276279 args.Total = result.Total;
277280 }
278281
279- async Task OnDropDownRead(DropDownListReadEventArgs args)
282+ private async Task OnDropDownRead(DropDownListReadEventArgs args)
280283 {
281- var result = DropDownData.ToDataSourceResult (args.Request);
284+ var result = await DropDownData.ToDataSourceResultAsync (args.Request);
282285 args.Data = result.Data;
283286 args.Total = result.Total;
284287 }
@@ -290,17 +293,15 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
290293 base.OnInitialized();
291294 }
292295
293- void GenerateData()
296+ private void GenerateData()
294297 {
295298 GridData = new List<SampleModel>();
296299 DropDownData = new List<SampleModel>();
297300
298- var rnd = new Random();
299-
300301 for (int i = 1; i <= ItemCounter; i++)
301302 {
302- GridData.Add(new SampleModel() { Id = i, Text = $"Text {rnd. Next(1, 100 )}" });
303- DropDownData.Add(new SampleModel() { Id = i, Text = $"Text {rnd. Next(1, 100 )}" });
303+ GridData.Add(new SampleModel() { Id = i, Text = $"Text {(char)Random.Shared. Next(65, 91)}{(char)Random.Shared.Next(65, 91 )}" });
304+ DropDownData.Add(new SampleModel() { Id = i, Text = $"Text {(char)Random.Shared. Next(65, 91)}{(char)Random.Shared.Next(65, 91 )}" });
304305 }
305306
306307 ItemCounter++;
@@ -309,7 +310,7 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
309310 public class SampleModel
310311 {
311312 public int Id { get; set; }
312- public string Text { get; set; }
313+ public string Text { get; set; } = string.Empty;
313314 }
314315}
315316````
0 commit comments