Editing a custom table item

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The code example below demonstrates how an existing item in a custom table can be edited.




using CMS.CMSHelper;

using CMS.SettingsProvider;

using CMS.SiteProvider;

using CMS.DataEngine;




        string customTableClassName = "customtable.SampleTable";


        // Get data class using custom table name

        DataClassInfo customTableClassInfo = DataClassInfoProvider.GetDataClass(customTableClassName);

        if (customTableClassInfo == null)


            throw new Exception("Given custom table does not exist.");



      // Initialize custom table item provider with current user info and general connection

      CustomTableItemProvider ctiProvider = new CustomTableItemProvider(CMSContext.CurrentUser, ConnectionHelper.GetConnection());


        // Provide ID of item you want to edit

        int itemId = 1;


        // Get custom table item with given ID

        CustomTableItem item = ctiProvider.GetItem(itemId, customTableClassInfo.ClassName);


        // Set value of the custom table item field

        item.SetValue("ItemText""Sample item");


        // Update item



Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_editing_a_custom_table_item.htm