Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Using alternative form on custom table View modes: 
User avatar
Certified Developer v6
Certified Developer v6
allan.andal-gmail - 5/15/2011 11:43:50 PM
   
Using alternative form on custom table
I cloned CustomRegistration webpart and adjust the code / usage so that instead of registration form, I have data entry for my custom table.. the approach is using alternative form.. however I got stucked on this line on SetupControl method.
formCustTable.AlternativeFormFullName = this.AlternativeForm;
formCustTable.Info = new ???;

Is this even possible? Does anyone here tried to use alternative form for custom table using API?

User avatar
Member
Member
kentico_michal - 5/16/2011 5:49:41 AM
   
RE:Using alternative form on custom table
Hello,

It should be possible use the ClassName property instead of the Info property:

formCustTable.ClassName = "customtable.tablename";

However, I would recommend using special control called CMS:CustomTableForm that is intended to display and work with custom tables. Please take a look at following example:
<CMS:CustomTableForm id="tblform" runat="server" />

CODE BEHIND:

protected override void OnInit(EventArgs e)
{
tblform.ShowPrivateFields = true;
tblform.CustomTableId = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("customtable.tablename").ClassID;
tblform.FormMode = CMS.FormEngine.FormModeEnum.Update;
tblform.AlternativeFormFullName = "customtable.test.AlternativeForm";
tblform.ItemID = 3;
}

Best regards,
Michal Legen

User avatar
Member
Member
farbod.kishani-gmail - 12/1/2011 3:28:59 AM
   
RE:Using alternative form on custom table
Hello,
I created new Custom Table: "NewsDepartment" then I created an Alternative form for this custom table "InsertDep" for insert NewsDepartment. then I created a modoul and added it's folder under "CMSModules" folder like I should do.
then I added a user control and added a CMS:CustomTableForm to that user control like this:
<asp:Content ID="cntBody" runat="server" ContentPlaceHolderID="plcContent">
<cms:CustomTableForm id="tblform" runat="server" />
</asp:Content>

and in Code behind:

protected override void OnInit(EventArgs e)
{
tblform.ShowPrivateFields = true;
tblform.CustomTableId = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("customtable.NewsDepartment").ClassID;
tblform.FormMode = CMS.FormEngine.FormModeEnum.Insert;
tblform.AlternativeFormFullName = "customtable.NewsDepartment.InsertDep";
tblform.ItemID = 3;
}

when I run project and want to work with that modul I get this error:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Custom table record which is intended to update does not exist.

I already checked CMS_Class table and the record for my Custom table is there and when i put break point in this line:
 tblform.CustomTableId = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("customtable.NewsDepartment").ClassID;

it returns CustomTableId properly. so what is the Problem?
Thank you.

User avatar
Member
Member
kentico_michal - 12/2/2011 2:57:45 AM
   
RE:Using alternative form on custom table
Hello,

This error message is usually displayed when you are updating some item which does not exist.

So, please make sure that the record with the ItemID = 3 exists.

Best regards,
Michal Legen

User avatar
Member
Member
farbod.kishani-gmail - 12/3/2011 4:07:55 AM
   
RE:Using alternative form on custom table
Hello,
acctually I dont know what is that "ItemID" and I just copied from your code that you wrote above.
what is "ItemID" and how can I get it?
thank you

User avatar
Member
Member
kentico_michal - 12/4/2011 11:30:21 PM
   
RE:Using alternative form on custom table
Hello,

If you want to update some custom table record, you need to set at least two properties:
the FormMode property to FormModeEnum.Update
the ItemID property needs to be set ID of the record you want to update [you can get it either directly in the database or in the CMS Desk -> Tools -> Custom tables -> edit custom table].

On the other side, if you want to add a new custom table item, you need to set the FormMode property to FormModeEnum.Insert. In this case, the ItemID does not need to be specified.

In both cases, you need to set also the CustomTableId and AlternativeFormfullName.

ItemID can be also obtained by using Kentico CMS API for custom tables: Custom tables API examples

Best regards,
Michal Legen