I tried to bound Datatable as source to telerik blazor gird

0 Answers 26 Views
Getting started with ASP.NET Miscellaneous
Nikilesh
Top achievements
Rank 1
Nikilesh asked on 02 Dec 2023, 06:00 AM

<TelerikGrid Data="@GetRows()" TItem="DataRow" PageSize="5">
    <GridColumns>
        @foreach (DataColumn column in dataTable.Columns)
        {
            <GridColumn Field="@column.ColumnName" Title="@column.ColumnName" />
        }
    </GridColumns>
</TelerikGrid>

@code {
    private DataTable dataTable;

    protected override void OnInitialized()
    {
        dataTable = new DataTable("MyDataTable");
        dataTable.Columns.Add("ID", typeof(int));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Rows.Add(1, "John");
        dataTable.Rows.Add(2, "Jane");
    }

    private IEnumerable<DataRow> GetRows()
    {
        return dataTable.Rows.Cast<DataRow>();
    }
}   

 

this code not working .Is there any other ways?

Jeremy
Top achievements
Rank 1
commented on 19 Dec 2023, 01:29 PM

 If the data is binding but not displaying correctly, try explicitly setting the Template property of your GridColumn elements to customize the rendering of each cell.

No answers yet. Maybe you can help?

Tags
Getting started with ASP.NET Miscellaneous
Asked by
Nikilesh
Top achievements
Rank 1
Share this question
or