1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Create custom field : FieldControl

Create custom field : FieldControl

2 posts, 0 answered
  1. Nuno
    Nuno avatar
    9 posts
    Registered:
    04 Jan 2013
    30 Jan 2013
    Link to this post
    Hello again,
    I'm trying to create a Custom Field Control with a RadGrid (with options to edit, delete and insert) but without success. The events of RadGrid doesn't fire...
    CODE .ACSX
    <div>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" EnableAJAX="true">
            <telerik:RadGrid ID="rgCosts" runat="server"  EnableViewState="true"
                AllowPaging="false" AllowSorting="false" AllowFilteringByColumn="false">
                <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="Id"
                    InsertItemPageIndexAction="ShowItemOnCurrentPage">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ConfirmText="Delete this item?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"
                            ConfirmDialogWidth="220px">
                        </telerik:GridButtonColumn>
                        <telerik:GridTemplateColumn DataField="Id" HeaderText="Id" UniqueName="Id"
                            Visible="false">
                            <InsertItemTemplate>
                                <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Id") %>'
                                    Width="150px">
                                </telerik:RadTextBox>
                            </InsertItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Eval("Id") %>'
                                    ReadOnly="true" Width="150px">
                                </telerik:RadTextBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        </telerik:RadWindowManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
    </div>

    CODE .ASCX.CS
    protected virtual RadGrid RadGridViewControl
            {
                get
                {
                    return this.Container.GetControl<RadGrid>("rgCosts", true);
                }
            }
    ...
    protected override void InitializeControls(GenericContainer container)
            {
                this.RadGridViewControl.NeedDataSource += RadGridViewControl_NeedDataSource;
                this.RadGridViewControl.DeleteCommand += RadGridViewControl_DeleteCommand;
                this.RadGridViewControl.InsertCommand += RadGridViewControl_InsertCommand;
                this.RadGridViewControl.UpdateCommand += RadGridViewControl_UpdateCommand;
            }
    ...
    protected void RadGridViewControl_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                ParticipationCostCollection p = new ParticipationCostCollection();
                p.Add(new ParticipationCostItem() { Id = Guid.NewGuid(), Title = "the title", Observations = "qwerty", ValueCompanyC = 25, ValueCompanyNC = 30 });
                p.Add(new ParticipationCostItem() { Id = Guid.NewGuid(), Title = "the title 2", Observations = "asdfg", ValueCompanyC = 45, ValueCompanyNC = 50 });
                this.RadGridViewControl.DataSource = p;
            }
     
            protected void RadGridViewControl_UpdateCommand(object sender, GridCommandEventArgs e)
            {
                //TODO
            }
     
            protected void RadGridViewControl_InsertCommand(object sender, GridCommandEventArgs e)
            {
                //TODO
            }
     
            protected void RadGridViewControl_DeleteCommand(object sender, GridCommandEventArgs e)
            {
                //TODO
            }

    Thanks for the help
    NS
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    01 Feb 2013
    Link to this post
    Hello Nuno,

    Are you creating a field control or a custom control? Did you followed our documenation about creating field controls?

    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/controls/types-of-controls/field-controls/building-a-custom-field-control

    Also, in every module you are able to add custom fields from type Long Text, which are practically RadEditors. Why do you need to create your own field?

    Kind regards,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered