Good day, I have a question relating to Sf DropDown List component. I have this code right now:
<SfDropDownList ID="productType" TValue="string[]" TItem="ProductTypes" DataSource="@ProductVals" @bind-Value="@defaultVal" Placeholder="Product Type">
<DropDownListTemplates>
<ItemTemplate Context="productType">
<option value="@((int)ProductTypes.Regular)">@(ProductTypes.Regular.ToString())</option>
<option value="@((int)ProductTypes.Service)">@(ProductTypes.Service.ToString())</option>
</ItemTemplate>
</DropDownListTemplates>
</SfDropDownList>
<ValidationMessage For="() => product.ProductType" />
And this c# that I am trying to bind to:
public int ProductType { get; set; } = (int)ProductTypes.Regular; // integer
public string[] ProductVals = Enum.GetNames(typeof(ProductTypes));
public ProductTypes defaultVal { get; set; } = ProductTypes.Regular;
public enum ProductTypes
{
Regular = 1,
Service = 2,
Replacement = 3,
Group = 4,
}
Yet this method is throwing a multitude of errors, like "cannot convert type to string", and "cannot convert lambda expression to type", etc. Any help would be greatly appreciated. Please note I only wish to bind the first two values from PublicTypes, as there are two options.
|
<SfDropDownList ID="productType" TValue="ProductTypes" TItem="string" DataSource="@ProductVals" @bind-Value="@defaultVal" Placeholder="Product Type"> SfDropDownList> |
|
public int ProductType { get; set; } = (int)ProductTypes.Regular; // integer
public string[] ProductVals = Enum.GetNames(typeof(ProductTypes)).Take(2).ToArray();// To select only 2 items
public ProductTypes defaultVal { get; set; } = ProductTypes.Regular;
public enum ProductTypes
{
Regular = 1,
Service = 2,
Replacement = 3,
Group = 4,
} |
Hello, thank you for your help. One more question: how to convert this type of dropdown to SyncFusion?
<SfDropDownList ID="productPackBreak" @bind-Value="@product.PackBreakParent" Placeholder="Pack Break Parent"> *@
@* <DropDownListTemplates> *@
@* <ItemTemplate Context="productType"> *@
@* <option value="0">(None)</option> *@
@* @foreach (var p in ProductsWithoutPackChild) *@
@* { *@
@* <option value="@p.Id">@p.LookupCode - @p.Description</option> *@
@* } *@
@* </ItemTemplate> *@
@* </DropDownListTemplates> *@
@* </SfDropDownList> *@
public int? PackBreakParent { get; set; }
PackBreakParent is not an enum.
ProductBases = PosDb.ProductBases.OrderBy(i => i.Description).ToList();
ProductsWithoutPackChild = (from p in PosDb.Products
from pParent in PosDb.Products.LeftJoin(i => i.PackBreakParent == p.Id)
where p.ProductType == (int)ProductTypes.Regular &&
((product.Id > 0 && p.Id != product.Id && pParent == null) || product.PackBreakParent == p.Id ||
(product.Id == 0 && pParent == null))
orderby p.Description
select p).ToList();
ProductsForReplace = PosDb.Products.Where(i =>
i.ProductType == (int) ProductTypes.Regular && i.Id != product.Id && !i.IsDisabled)
.OrderBy(i => i.Description).ToList();