Kentico CMS 7.0 Developer's Guide

Managing web part containers

Managing web part containers

Previous topic Next topic Mail us feedback on this topic!  

Managing web part containers

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 container.

 

private void CreateWebPartContainer()
{
    // Create new web part container object
    WebPartContainerInfo newContainer = new WebPartContainerInfo();
 
    // Set the properties
    newContainer.ContainerDisplayName = "My new container";
    newContainer.ContainerName = "MyNewContainer";
    newContainer.ContainerTextBefore = "<div class=\"myNewContainer\">";
    newContainer.ContainerTextAfter = "</div>";
 
    // Save the web part container
    WebPartContainerInfoProvider.SetWebPartContainerInfo(newContainer);
}

 

The following example gets and updates a container.

 

private bool GetAndUpdateWebPartContainer()
{

  // Get the web part container

  WebPartContainerInfo updateContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

    if (updateContainer != null)
    {

      // Update the properties
       updateContainer.ContainerDisplayName = updateContainer.ContainerDisplayName.ToLower();

 

        // Save the changes
        WebPartContainerInfoProvider.SetWebPartContainerInfo(updateContainer);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates containers.

 

private bool GetAndBulkUpdateWebPartContainers()
{
    // Prepare the parameters
    string where = "ContainerName LIKE N'MyNewContainer%'";
    string orderBy = "";
    int topN = 0;
    string columns = "";

 

  // Get the data

  DataSet containers = WebPartContainerInfoProvider.GetContainers(where, orderBy, topN, columns);

    if (!DataHelper.DataSourceIsEmpty(containers))
    {
        // Loop through the individual items
        foreach (DataRow containerDr in containers.Tables[0].Rows)
        {

          // Create object from DataRow
          WebPartContainerInfo modifyContainer = new WebPartContainerInfo(containerDr);

 
          // Update the properties
           modifyContainer.ContainerDisplayName = modifyContainer.ContainerDisplayName.ToUpper();

 
            // Save the changes
            WebPartContainerInfoProvider.SetWebPartContainerInfo(modifyContainer);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a web part container.

 

private bool DeleteWebPartContainer()
{

  // Get the web part container
  WebPartContainerInfo deleteContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

 
    // Delete the web part container
    WebPartContainerInfoProvider.DeleteWebPartContainerInfo(deleteContainer);
 
    return (deleteContainer != null);
}