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

[Solved] Hide Missing DataSet Columns

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martín
Top achievements
Rank 1
Martín asked on 16 Jan 2008, 05:19 PM
Hi there, I have a RadGrid Prometheus bound to and ODS that returns a DataSet. However this DataSet sometimes comes without some of the columns that are predefined in the grid which shows "System.Data.DataRowView" where the column data would be. How can I instruct the RadGrid to detect and hide this missing columns ?

Thanks!!

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 18 Jan 2008, 11:31 AM
Hi Martín,

You can wire ItemDataBound event and obtain e.Item.DataItem, which will be a DataRowView object. You can then check the presence of each column from RadGrid in datarowview's datatable. Then just hide the grid columns that are not present. ItemDataBound is fired for each item, but you will need this check only once, so you can add a boolean flag. Here is an example:

bool check = false
    protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && !check) 
        { 
            check = true
            DataTable tbl = ((DataRowView)e.Item.DataItem).DataView.Table; 
            foreach (GridBoundColumn col in RadGrid1.MasterTableView.Columns) 
            { 
                if (!tbl.Columns.Contains(col.DataField)) 
                { 
                    col.Visible = false
                } 
            } 
        } 
    } 

Hope this helps.

Greetings,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Martín
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or