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

All grid cells display 'system.data.datarowview'

1 Answer 533 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 21 Jul 2010, 06:19 PM
Hi,

I'm adding a RadGrid to a page and am having issues getting my table data to display.

The grid is generally working, but every cell displays as 'system.data.datarowview' - looks like it's calling ToString() on the wrong object?

I am populating the grid entirely in code, but am declaring it statically in my ASPX.
I create the columns in the Page_Load method (when !IsPostback) - there is a variety of GridBoundColumns and GridHyperlinkColumns. The columns are instantiated, added to the grid.MasterTableView.Columns collection, and *then* have additional properties set.

When the time comes to populate the grid (during a partial postback event), I have a helper class that produces a DataTable object with columns with names that match the GridColumns in the grid.

I finally call Rebind() and set the DataSource of the grid to my DataTable in the NeedDataSource event.

When stepping through some of the events (I create a custom paging control), I can clearly see that my data is present in the DataSource, but it's not making it through to the grid.

If I set the grid to AutoGenerateColumns=true in my ASPX, I get duplicate columns, but the auto generated ones are displaying my cell data correctly.

I suspect I'm missing some step in wiring the DataTable columns to the GridColumns. Any advice?

Thanks,
Stefan

1 Answer, 1 is accepted

Sort by
0
Stefan
Top achievements
Rank 1
answered on 21 Jul 2010, 07:01 PM
Duh. I wasn't explicitly mapping the GridColumns to the DataColumns in my DataSource.

I just got it working as expected. If anyone searches this in the future, here's the first revision of the code that is working for me:

GridColumn column;
if (IsHyperLink)
    column = new GridHyperLinkColumn();
else
    column = new GridBoundColumn();
 
grid.MasterTableView.Columns.Add(column);
 
if (column is GridHyperLinkColumn)
    (column as GridHyperLinkColumn).DataTextField = Name;
else if (column is GridBoundColumn)
    (column as GridBoundColumn).DataField = Name;
 
column.HeaderText = Name;

The second if/else explicitly maps the GridColumns to the DataColumn name I've been using.

Note that the GridColumn base class doesn't support the DataField property so a little extra code is needed to handle the various types.
Tags
Grid
Asked by
Stefan
Top achievements
Rank 1
Answers by
Stefan
Top achievements
Rank 1
Share this question
or