This is a migrated thread and some comments may be shown as answers.

RadGrid and a CSV File

3 Answers 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 25 Oct 2010, 10:56 PM
I have a CsvReader class that populates a DataTable from a csv formatted file. The file has no headers, the basic layout of the csv file is
1231,13213,1421,12414 (Obviously fake data)

I'm having trouble trying to figure out how I take this information and create a hierarchy in my RadGrid. The first value in the row is my parent and the other values are the children.

I've been trying to follow along the tutorials and demo's but for some reason it is not clicking.

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 27 Oct 2010, 07:32 AM
Hello Chris,

For example if csv is something like:
0,1
1,2,3,4,5
3,6,7,10
5,12,13
10,4124
And the first number of each row is parent and other are children, you can use the below code-snippet to create self hierarchy grid.

Aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="true"
        DataKeyNames="ID,ParentID" Width="100%">
        <SelfHierarchySettings ParentKeyName="ParentID" KeyName="ID" />
    </MasterTableView>
</telerik:RadGrid>
Code-behind:
protected DataTable MakeDataTable()
{
    DataTable table = new DataTable();
    table.Columns.Add(new DataColumn("ID"));
    table.Columns.Add(new DataColumn("ParentID"));
 
    using (StreamReader reader = new StreamReader("./data.csv"))
    {
        while (true)
        {
            string line = reader.ReadLine();
            if (line == null)
            {
                break;
            }
            else
            {
                string[] numbersAsStr = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                int parent = int.Parse(numbersAsStr[0]);
                for (int i = 1; i < numbersAsStr.Length; i++)
                {
                    int current = int.Parse(numbersAsStr[i]);
                    table.Rows.Add(current, parent);
                }
            }
        }
    }
    return table;
}



Best wishes,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cesar
Top achievements
Rank 1
answered on 05 Jan 2011, 03:17 PM
I have one problem to read a CSV file with RadUpload and Button and show in RadGrid, when i try to load Data don't show anything but when i try to open the file with code and without RadUpload and button control, the Grid Loads Perfectly.

0
Vasil
Telerik team
answered on 07 Jan 2011, 04:33 PM
Hello Chris,

Can you show us the code that you use to bind the grid after uploading the CSV file?

Kind regards,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Cesar
Top achievements
Rank 1
Share this question
or