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

Get both row headers and column headers in telerik's radgrid

3 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ronan BARRANGER
Top achievements
Rank 1
Ronan BARRANGER asked on 19 Jun 2012, 02:44 PM
 

I'm facing a problem with the use of the telerik's radgrid. So far i have been using simple grids with only column headers. I need know to get row headers.

I'm trying to work with this which is more or less what i am looking for : http://demos.telerik.com/aspnet-ajax/grid/examples/programming/pivot/defaultcs.aspx

the problem the Row/Column headers are not the column names from my table. I need to write them directly in the code.
Some help would be welcome! thanks in advance

3 Answers, 1 is accepted

Sort by
0
Ronan BARRANGER
Top achievements
Rank 1
answered on 25 Jun 2012, 07:27 AM
no one knows ? :(
0
Shinu
Top achievements
Rank 2
answered on 25 Jun 2012, 09:43 AM
Hi,

Try the following code snippet to give row header manually.

C#:
public DataTable PivotTable(DataTable source)
{
    DataTable dest = new DataTable("Pivoted" + source.TableName);
    dest.Columns.Add(" ");
    foreach (DataRow r in source.Rows)
        dest.Columns.Add(r[0].ToString());
    for (int i = 0; i < source.Columns.Count - 1; i++)
    {
        dest.Rows.Add(dest.NewRow());
    }
    for (int r = 0; r < dest.Rows.Count; r++) 
    {
        for (int c = 0; c < dest.Columns.Count; c++)
        {
            if (c == 0)
            {
                dest.Rows[0][0] = "heading1"; // code for giving row header manually
                dest.Rows[1][0] = "heading2";
                dest.Rows[2][0] = "heading3";
                dest.Rows[3][0] = "heading4";
                . . .
                . . .
            }
            else
                dest.Rows[r][c] = source.Rows[c - 1][r + 1];
        }
    }
    dest.AcceptChanges();
    return dest;
}
protected void RadGrid1_NeedDataSource1(object source, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = PivotTable(GetDataTable("SELECT TOP 5 CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode, City, Country FROM Customers"));
}

Thanks,
Shinu.
0
Ronan BARRANGER
Top achievements
Rank 1
answered on 26 Jun 2012, 07:43 AM
Thanks!
Tags
Grid
Asked by
Ronan BARRANGER
Top achievements
Rank 1
Answers by
Ronan BARRANGER
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or