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

Using RadGrid as part of a composite server control

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 19 Sep 2011, 11:36 AM
I am not sure if that will be the right place to ask.
I am writing a asp.net composite server control, which will have a RadGrid as part of it. I don't want to expose the whole grid as a public property though, instead I would like to expose just GridColumnCollection part. 

GridColumnsCollection is a read-only property though so I can't write the code below:
[
    Category("Grid"),
    Description("Columns for a grid."),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    PersistenceMode(PersistenceMode.InnerProperty)
]
public GridColumnCollection GridColumns
{
    get
    {
        EnsureChildControls();
        return grid.MasterTableView.Columns;
    }
    set
    {
        EnsureChildControls();
        grid.MasterTableView.Columns = value;
    }
}

When I am trying to change it to something like the code below, I will get an error saying that GridColumnCollection does not have constructor which takes 0 arguments.
    Category("Grid"), 
    Description("Columns for a grid."), 
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 
    PersistenceMode(PersistenceMode.InnerProperty) 
public GridColumnCollection GridColumns 
    get 
    
        EnsureChildControls(); 
        return grid.MasterTableView.Columns; 
    
    set 
    
        EnsureChildControls(); 
        foreach(GridColumn col in value)
        {
                 grid.MasterTableView.Columns.Add(col); 
        }
    
}

Is there any way to expose just columns from RadGrid as a property of a composite server control?

Thanks,

Daniel

1 Answer, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 19 Sep 2011, 03:04 PM
The topic has been closed as I have found the way to do it (described below).

I fixed it, it seems like I had to set only get{} for the given property:
[      
    Category("Grid"),      
    Description("Columns for a grid."),      
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),      
    PersistenceMode(PersistenceMode.InnerProperty)  
]  
public GridColumnCollection GridColumns  
{      
    get     
    {          
        EnsureChildControls();         
        return grid.MasterTableView.Columns;      
    }  
}







Now when using control I can write:

<c:myGrid>     
    <gridColumns>         
         (..List of columns like I would normally do with Teleriks RadGrid..)     
    </gridColumns
</c:myGrid>
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Share this question
or