Example #1
0
    public List <ElementItemHeaderInfo> GetElements(
        string sectionName,
        string elementName,
        string virtualPath,
        string site,
        string locationSubPath,
        string server)
    {
        List <ElementItemHeaderInfo> elementList =
            new List <ElementItemHeaderInfo>();

        Configuration config =
            WebConfigurationManager.OpenWebConfiguration(
                virtualPath, site, locationSubPath, server);

        ConfigurationSection cs = config.GetSection(sectionName);

        Type sectionType = cs.GetType();

        System.Reflection.PropertyInfo reflectionElement =
            sectionType.GetProperty(elementName);
        Object elementObject = reflectionElement.GetValue(cs, null);

        Type elementType = elementObject.GetType();

        System.Reflection.PropertyInfo reflectionProperty =
            elementType.GetProperty("Count");

        if (reflectionProperty != null)
        {
            int elementCount =
                Convert.ToInt32(reflectionProperty.GetValue(
                                    elementObject, null));
            for (int i = 0; i < elementCount; i++)
            {
                ElementItemHeaderInfo ei = new ElementItemHeaderInfo();
                ei.ItemName = String.Format(
                    "Item {0} of {1}", i + 1, elementCount);
                ei.Index       = i;
                ei.Name        = elementName;
                ei.SectionName = sectionName;
                elementList.Add(ei);
            }
        }
        else
        {
            ElementItemHeaderInfo ei = new ElementItemHeaderInfo();
            ei.Name        = elementName;
            ei.ItemName    = "Item 1 of 1";
            ei.SectionName = sectionName;
            elementList.Add(ei);
        }
        return(elementList);
    }
Example #2
0
    // <Snippet92>
    protected void ListView1_ItemDataBound(
        object sender, ListViewItemEventArgs e)
    {
        ElementItemHeaderInfo ei = e.Item.DataItem
                                   as ElementItemHeaderInfo;

        ObjectDataSource ods = (ObjectDataSource)e.Item.FindControl("InnerObjectDataSource");

        ods.SelectParameters["sectionName"].DefaultValue = ei.SectionName;
        ods.SelectParameters["elementName"].DefaultValue = ei.Name;
        ods.SelectParameters["index"].DefaultValue       = ei.Index.ToString();
        //propertiesListView.DataBind();
    }