I am creating an app in Blazor/C#, using mostly Radzen components. My goal is to have a user select the number of items to add, using RadzenNumeric, and then dynamically create that number of text boxes.
I found a working example, that almost fits my needs, with . but, I can't seem to get it to fire from the RadzenNumeric Change="@onchange_n".
Here is what I had so far:
<RadzenNumeric Value="@N" class="w-100" Change="@onchange_n" /> Sum: @total
I feel that it's the Value attribute that I am getting wrong. I based it on the working example I found below. This one works:
<input type="number" value="@N" @oninput="onchange_n"> Sum: @total
Code:
@foreach (var i in Enumerable.Range(0,N))
{
var ii=i;
<input type="number" value="@MyList[ii]"
@oninput="(e) => resum(ii, e)"><br>
}
@code
{
private int N = 0, total = 0;
private List<int> MyList = new List<int>();
private Void onchange_n(ChangeEventArgs e)
{
N=0;
if (Int32.TryParse(e.Value.ToString(), out int n)) N = n
MyList.Clear();
MyList.AddRage(Enumerable.Range(0,N).Select(_=>0));
StateHasChanged();
}
private void resum(int i, ChangeEventArgs e)
{
var n = 0;
if (Int32.TryParse(e.Value.ToString(), out int auxn)) n = auxn;
MyList[i] = n;
total = MyList.Sum(x=>x);
}
}
I don't understand why it will fire onchange_n properly from the (<input type="number") box, but not the RadzenNumeric. is Value not the proper place for @N ? what am I missing.?