I am trying to code a page with a grid with 2 columns:
File Name
File Type (in a dropdown control)
I have up to 10 file names in a Data Class, and I am having a few errors before I can start debugging this page.
I am attaching the class with the file name, there is also a file count updated from a previous page (as well as the file names)
The way I built the data class is causing me problems.
Fields.cs (could not attach .cs file type)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Net.Http;
using System.Net.Http.Headers;
namespace server_sample.Data
{
public class Files
{
public static string Name1 { get; set; }
public static string Path1 { get; set; }
public static string Type1 { get; set; }
public static string Name2 { get; set; }
public static string Path2 { get; set; }
public static string Type2 { get; set; }
public static string Name3 { get; set; }
public static string Path3 { get; set; }
public static string Type3 { get; set; }
public static string Name4 { get; set; }
public static string Path4 { get; set; }
public static string Type4 { get; set; }
public static string Name5 { get; set; }
public static string Path5 { get; set; }
public static string Type5 { get; set; }
public static string Name6 { get; set; }
public static string Path6 { get; set; }
public static string Type6 { get; set; }
public static string Name7 { get; set; }
public static string Path7 { get; set; }
public static string Type7 { get; set; }
public static string Name8 { get; set; }
public static string Path8 { get; set; }
public static string Type8 { get; set; }
public static string Name9 { get; set; }
public static string Path9 { get; set; }
public static string Type9 { get; set; }
public static string Name10 { get; set; }
public static string Path10 { get; set; }
public static string Type10 { get; set; }
public static int Zfilecnt { get; set; }
}
}
And here is the component where I am trying to define each file type (with comments on the errors)
@page "/Define Files"
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Grids
@using server_sample.Data
<SfGrid @ref="GridRef" AllowPaging="true" DataSource="@GridData" Toolbar="@(new List<string>() { "Delete", "Update" })">
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="false" Mode="@EditMode.Normal"></GridEditSettings>
<GridEvents TValue="Files"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(File.Name) HeaderText="File Name" TextAlign="@TextAlign.Center" Width="240"></GridColumn>
<GridColumn Field=@nameof(File.Type) HeaderText="File Type" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="FileType" TItem="File" TValue="string" @bind-Value="@((context as File).Type)" DataSource="@FileTypes">
<DropDownListFieldSettings Value="CustomerID"></DropDownListFieldSettings>
<DropDownListEvents ValueChange="ValueChange" TValue="string" TItem="File"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(File.Name) HeaderText=" File Name" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipState" Placeholder="Select a State" TItem="string" Enabled="@Enabled" TValue="string" @bind-Value="@((context as Orders).ShipState)" DataSource="@States">
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code
{
// <DropDownListEvents ValueChange="ValueChange"
// this is giving me an error that "can not convert from 'method group' to 'eventcallback'
//
SfGrid<Files> GridRef;
public List<Files> GridData { get; set; } = new List<Files>();
public List<string> FileTypes = new List<string>() { "Fixed ", "Comma Delim", "Tab Delim", "Excel", "SemiColon Delim", "DBF", "PDF", "Word", "XML", "Jason" };
string aux="";
public bool Enabled = false;
public class Files
{
public Files()
{
}
public Files(string FileName, string FileType)
{
/// Error DefineFiles.Files does not contain a definition for FileName or TypeID
/// I've coded the Fields class to accomodate up to 10 files how should I code it...
///
this.FileName = FileName;
this.TypeID = FileType;
}
}
public void ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, string> args)
{
// have to retrieve selected row to find which Data.Files.Type to update...
//Data.Files.
/* if (args.Value == "United States")
{
States = new List<string>() { "New York", "Virginia", "Washington" };
}
else if (args.Value == "Australia")
{
States = new List<string>() { "Queensland", "Tasmania", "Victoria" };
}*/
Enabled = true;
GridRef.PreventRender(false);
}
public string FileID { get; set; }
public string TypeID { get; set; }
protected override void OnInitialized()
{
for (int i = 1; i <= Data.Files.Zfilecnt; i++)
{
aux = "Name" + i.ToString();
GridData.Add(new Files(aux, FileTypes));
}
}
public class File
{
public string Name { get; set; }
public string Path { get; set; }
public string Type { get; set; }
}
public void OnActionBegin(ActionEventArgs<Files> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
Enabled = false;
}
}
}
|
<GridColumn Field=@nameof(File.Type) HeaderText="File Type" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="FileType" TItem="File" TValue="string" @bind-Value="@((context as File).Type)" DataSource="@FileTypes">
<DropDownListFieldSettings Value="CustomerID"></DropDownListFieldSettings>
<DropDownListEvents ValueChange="ValueChange" TValue="string" TItem="File"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
//set based on TValue and TItem property
public void ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, File> args)
{
...
GridRef.PreventRender(false);
}
public class Files
{
public Files()
{
}
public Files(string FileName, string FileType)
{
this.FileName = FileName;
this.TypeID = FileType;
}
public string FileName { get; set; }
public string TypeID { get; set; }
} |
Thanks for your reply. I changed my code to:
@page "/Define Files"
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Grids
@using server_sample.Data
<SfGrid @ref="GridRef" AllowPaging="true" DataSource="@GridData" Toolbar="@(new List<string>() { "Delete", "Update" })">
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="false" Mode="@EditMode.Normal"></GridEditSettings>
<GridEvents TValue="Files"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(File.Name) HeaderText="File Name" TextAlign="@TextAlign.Center" Width="240"></GridColumn>
<GridColumn Field=@nameof(File.Type) HeaderText="File Type" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="FileType" TItem="File" TValue="string" @bind-Value="@((context as File).Type)" DataSource="@FileTypes">
<DropDownListFieldSettings Value="CustomerID"></DropDownListFieldSettings>
<DropDownListEvents ValueChange="ValueChange" TValue="string" TItem="File"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(File.Name) HeaderText=" File Name" EditType="EditType.DropDownEdit" Width="150">
<EditTemplate>
<SfDropDownList ID="ShipState" Placeholder="Select a State" TItem="string" Enabled="@Enabled" TValue="string" @bind-Value="@((context as Orders).ShipState)" DataSource="@States">
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
@code
{
SfGrid<Files> GridRef;
public List<Files> GridData { get; set; } = new List<Files>();
public List<string> FileTypes = new List<string>() { "Fixed ", "Comma Delim", "Tab Delim", "Excel", "SemiColon Delim", "DBF", "PDF", "Word", "XML", "Jason" };
string aux="";
public bool Enabled = false;
public class Files
{
public Files()
{
}
public Files(string FileName, string FileType)
{
this.FileName = FileName;
this.TypeID = FileType;
}
public string FileName { get; set; }
public string TypeID { get; set; }
}
public void ValueChange(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, string> args)
{
// have to retrieve selected row to find which Data.Files.Type to update...
//Data.Files.
/* if (args.Value == "United States")
{
States = new List<string>() { "New York", "Virginia", "Washington" };
}
else if (args.Value == "Australia")
{
States = new List<string>() { "Queensland", "Tasmania", "Victoria" };
}*/
Enabled = true;
GridRef.PreventRender(false);
}
public string FileID { get; set; }
public string TypeID { get; set; }
protected override void OnInitialized()
{
for (int i = 1; i <= Data.Files.Zfilecnt; i++)
{
aux = "Name" + i.ToString();
// /////////////////////////////////////////////////////// New Error
// getting warning CS1503 Argument 2 - Can not convert from System.Collections.Generic.List<string> to 'string'
GridData.Add(new Files(aux, FileTypes));
}
}
public class File
{
public string Name { get; set; }
public string Path { get; set; }
public string Type { get; set; }
}
public void OnActionBegin(ActionEventArgs<Files> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
Enabled = false;
}
}
}
I got the following compile errors
Severity Code Description Project File Line Suppression State
Error CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 1 Active
Error CS0246 The type or namespace name 'Orders' could not be found (are you missing a using directive or an assembly reference?) server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 1 Active
Error CS0246 The type or namespace name 'Orders' could not be found (are you missing a using directive or an assembly reference?) server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 1 Active
Error CS0246 The type or namespace name 'Orders' could not be found (are you missing a using directive or an assembly reference?) server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 1 Active
Error CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 1 Active
Error CS1503 Argument 1: cannot convert from 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.IEnumerable<server_sample.Pages.Define_Files.File>' server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 13 Active
Error CS1503 Argument 2: cannot convert from 'method group' to 'EventCallback' server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 15 Active
Error CS0246 The type or namespace name 'Orders' could not be found (are you missing a using directive or an assembly reference?) server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 21 Active
Error CS0103 The name 'States' does not exist in the current context server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 21 Active
Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.List<string>' to 'string' server-sample C:\Users\data\Downloads\Syncfusion\308\server-sample\Pages\Define Files.razor 79 Active
Warning CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\data\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. server-sample 1 Active
Warning CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\data\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn4.0\cs\System.Text.Json.SourceGeneration.dll: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. server-sample 1 Active
Hello Raul and Syncfusion Team
I am also concerned with my design I created a class with room for 10 files (internal names, url names, and file types (along with a count variable) Which are filled out on a previous component UPLOAD.
Once we get past the syntax error I intend to have a edit dropdown for a selected file/row and save the type on the same class (files.cs)
Please let me know if this is good design
Paul