Create custom field : FieldControl
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
>
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
Hello Nuno,
Are you creating a field control or a custom control? Did you followed our documenation about creating field controls?
www.sitefinity.com/.../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?