Exposgin Column Collection in a User Control for RadGrid

2 posts, 0 answers
  1. Jolly
    Jolly avatar
    3 posts
    Member since:
    Dec 2012

    Posted 25 Dec 2018 Link to this post

    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?

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4489 posts

    Posted 27 Dec 2018 Link to this post

    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.
Back to Top