Kentico CMS 6.0 Developer's Guide

Managing web part layouts

Managing web part layouts

Previous topic Next topic Mail us feedback on this topic!  

Managing web part layouts

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

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a web part layout.

 

private bool CreateWebPartLayout()
{
    // Get the web part
    WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart");
    if (webpart != null)
    {
        // Create new web part layout object
        WebPartLayoutInfo newLayout = new WebPartLayoutInfo();
 
        // Set the properties
        newLayout.WebPartLayoutDisplayName = "My new layout";
        newLayout.WebPartLayoutCodeName = "MyNewLayout";
        newLayout.WebPartLayoutWebPartID = webpart.WebPartID;

       newLayout.WebPartLayoutCode = "This is the new layout of MyNewWebpart webpart.";

 
        // Save the web part layout
        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(newLayout);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a layout.

 

private bool GetAndUpdateWebPartLayout()
{

  // Get the web part layout

  WebPartLayoutInfo updateLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart","MyNewLayout");

    if (updateLayout != null)
    {

      // Update the properties
       updateLayout.WebPartLayoutDisplayName = updateLayout.WebPartLayoutDisplayName.ToLower();

 

        // Save the changes
        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(updateLayout);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates layouts.

 

private bool GetAndBulkUpdateWebPartLayouts()
{
    // Prepare the parameters
    string where = "WebPartLayoutCodeName LIKE N'MyNewLayout%'";
 
    // Get the data
    DataSet layouts = WebPartLayoutInfoProvider.GetWebPartLayouts(where, null);
    if (!DataHelper.DataSourceIsEmpty(layouts))
    {
        // Loop through the individual items
        foreach (DataRow layoutDr in layouts.Tables[0].Rows)
        {
            // Create object from DataRow
            WebPartLayoutInfo modifyLayout = new WebPartLayoutInfo(layoutDr);

 

          // Update the properties

           modifyLayout.WebPartLayoutDisplayName = modifyLayout.WebPartLayoutDisplayName.ToUpper();

 
            // Save the changes
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(modifyLayout);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a web part layout.

 

private bool DeleteWebPartLayout()
{

  // Get the web part layout

  WebPartLayoutInfo deleteLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout");

 
    // Delete the web part layout
    WebPartLayoutInfoProvider.DeleteWebPartLayoutInfo(deleteLayout);
 
    return (deleteLayout != null);
}