@@ -220,7 +220,13 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
220
220
```` RAZOR
221
221
@using Telerik.DataSource.Extensions
222
222
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"
224
230
TItem="@SampleModel"
225
231
TValue="@int"
226
232
OnRead="@OnDropDownRead"
@@ -236,13 +242,10 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
236
242
</ItemTemplate>
237
243
</TelerikDropDownList>
238
244
239
- <TelerikButton ThemeColor="@ThemeConstants.Button.ThemeColor.Primary"
240
- OnClick="@RebindComponents">Rebind Components</TelerikButton>
241
-
242
245
<br />
243
246
<br />
244
247
245
- <TelerikGrid @ref="@TheGrid "
248
+ <TelerikGrid @ref="@GridRef "
246
249
TItem="@SampleModel"
247
250
OnRead="@OnGridRead"
248
251
AutoGenerateColumns="true"
@@ -251,34 +254,34 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
251
254
PageSize="5" />
252
255
253
256
@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; }
256
259
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();
259
262
260
- int DropDownValue { get; set; } = 1;
263
+ private int DropDownValue { get; set; } = 1;
261
264
262
- int ItemCounter { get; set; } = 3;
265
+ private int ItemCounter { get; set; } = 3;
263
266
264
- void RebindComponents()
267
+ private void RebindComponents()
265
268
{
266
- GenerateData(); // simulate change in the data
269
+ GenerateData(); // simulate data change
267
270
268
- TheGrid .Rebind();
269
- TheDropDown .Rebind();
271
+ GridRef? .Rebind();
272
+ DropDownListRef? .Rebind();
270
273
}
271
274
272
- async Task OnGridRead(GridReadEventArgs args)
275
+ private async Task OnGridRead(GridReadEventArgs args)
273
276
{
274
- var result = GridData.ToDataSourceResult (args.Request);
277
+ var result = await GridData.ToDataSourceResultAsync (args.Request);
275
278
args.Data = result.Data;
276
279
args.Total = result.Total;
277
280
}
278
281
279
- async Task OnDropDownRead(DropDownListReadEventArgs args)
282
+ private async Task OnDropDownRead(DropDownListReadEventArgs args)
280
283
{
281
- var result = DropDownData.ToDataSourceResult (args.Request);
284
+ var result = await DropDownData.ToDataSourceResultAsync (args.Request);
282
285
args.Data = result.Data;
283
286
args.Total = result.Total;
284
287
}
@@ -290,17 +293,15 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
290
293
base.OnInitialized();
291
294
}
292
295
293
- void GenerateData()
296
+ private void GenerateData()
294
297
{
295
298
GridData = new List<SampleModel>();
296
299
DropDownData = new List<SampleModel>();
297
300
298
- var rnd = new Random();
299
-
300
301
for (int i = 1; i <= ItemCounter; i++)
301
302
{
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 )}" });
304
305
}
305
306
306
307
ItemCounter++;
@@ -309,7 +310,7 @@ Also check [how to rebind and refresh a component with a `Timer`](slug://common-
309
310
public class SampleModel
310
311
{
311
312
public int Id { get; set; }
312
- public string Text { get; set; }
313
+ public string Text { get; set; } = string.Empty;
313
314
}
314
315
}
315
316
````
0 commit comments