Datagrid bind datatable

Hi,

I follow the example of DataGrid dynamic data support. But my data is a DataTable alread. How can I bind it to the "RadzenDataGrid". Since the columns.key in dictionary can't duplicated. But my data has a lots duplicated data which failed put them the the key.

I am try to using.

public class ItemData
{
public string key { get; set; }
public object value { get; set; }
}

Any help.

Thanks,

JianJing

public IEnumerable<List> data { get; set; }

...

@data.ElementAt(i) //what to do here?

some code

Blockquote

"

<Template>
>                                     @data.ElementAt(i)
>                                 </Template>"

Hi @jjqin,

I am afraid I don't understand anything from your posts. Try editing them and formatting your code according to our forum FAQ.

@jjqin I convert my datatable to dictionaries with code like this:


                var columns = new Dictionary<string, Type>();
                var data = new List<IDictionary<string, object>>();

                foreach (DataColumn column in result.Columns)
                {
                    columns.Add(column.ColumnName, column.DataType);
                }

                foreach (DataRow row in result.Rows)
                {
                    var item = new Dictionary<string, object>();
                    foreach (DataColumn column in result.Columns)
                    {
                        item.Add(column.ColumnName, row[column]);
                    }
                    data.Add(item);
                }

And then I populate the grid with it like this:

<RadzenDataGrid @ref="dataGrid" Data="@data" TItem="IDictionary<string, object>" Count="@count" IsLoading="@isLoading" LoadData="@DataGridLoadData" ColumnWidth="95px" Density="Density.Compact" CellClick="@dataGridCellClick" style="height: 630px; width: 100%"> 
            <Columns>
                @foreach (var key in columns.Keys)
                {
                    @if(key == "StudentID"){
                        <RadzenDataGridColumn TItem="IDictionary<string, object>" Title="@key" Property="@key" Visible="false">
                        </RadzenDataGridColumn>
                    }
                    else if(key == "DOB")
                    {
                        <RadzenDataGridColumn TItem="IDictionary<string, object>" Title="@key" Property="@key" Width="150px">
                            <Template Context="data">
                                @if ((data as IDictionary<string, object>).ContainsKey(key))
                                {
                                    <span>@(String.Format("{0:d}", (data as IDictionary<string, object>)[key]))</span>
                                }
                            </Template>
                        </RadzenDataGridColumn>
                    }
                    else
                    {
                        <RadzenDataGridColumn TItem="IDictionary<string, object>" Title="@key" Property="@key">
                            <Template Context="data">
                                @if ((data as IDictionary<string, object>).ContainsKey(key))
                                {
                                    <span>@((data as IDictionary<string, object>)[key])</span>
                                }
                            </Template>
                        </RadzenDataGridColumn>
                    }
                }
            </Columns>
        </RadzenDataGrid>

If your datatable has duplicate keys, then I don't think you're creating it correctly. Hope this helps,
Slosuenos