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

Exposgin Column Collection in a User Control for RadGrid

1 Answer 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jolly
Top achievements
Rank 1
Jolly asked on 25 Dec 2018, 09:57 AM

I was trying to create a User Control for standardizing the Grid Control across all the forms. Surely all the forms will have different columns but the layout is the same across except for few properties here and there. How do I expose the Column Collection?

My Code would be:

<telerik:RadGrid ID="grid" runat="server" AllowCustomPaging="false" AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False" CellPadding="0" CellSpacing="0" CssClass="gridCandidate" Height="100%" Width="100%">
        <ClientSettings EnableAlternatingItems="false" EnableRowHoverStyle="true">
            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
            <Selecting AllowRowSelect="True" />
            <ClientEvents OnRowDataBound="function() {}" OnCommand="function(){}" />
        </ClientSettings>
        <MasterTableView AllowFilteringByColumn="False" AllowNaturalSort="false" ClientDataKeyNames="ID" DataKeyNames="ID" EnableColumnsViewState="False" EnableViewState="False" HierarchyLoadMode="Client"
            NoMasterRecordsText="<div class='noRec'>No records to display.</div>" TableLayout="Auto">
            <Columns></Columns>
<HeaderStyle Height="0px" />
            <PagerStyle Visible="False" />
        </MasterTableView>
    </telerik:RadGrid>

 

 

[MergableProperty(false), DefaultValue((string)null),
PersistenceMode(PersistenceMode.InnerProperty)]
public GridColumnCollection Columns
{
    get
    {
        return grid.Columns;
    }
    set
    {
        foreach (GridColumn column in value)
        {
            grid.MasterTableView.Columns.Add(column);
        }
        //grid.MasterTableView.Columns.Add()
    }
}

 

Any idea how to expose the Columns property?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 27 Dec 2018, 04:59 PM
Hello,

Perhaps the following thread can help you get started with this: https://stackoverflow.com/questions/120997/asp-nested-tags-in-a-custom-user-control.

You may also find it easier to set settings globally if you implement a control adapter, a ASP.NET Theme or to inherit RadGrid to your own class with some defaults. 

Of course, the choice would be entirely up to the application development team and their preferences, as neither of these features is related to our controls and is an architectural decision that is in the scope of the application logic and developer preferences.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jolly
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or