Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009

I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta an ASP.NET MVC application written in C#.NET.

Some of My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Shahed Khan blog
Note: If you are not familiar with writing UIProperty for SmartCodeGenerator please read this tutorial blog first:

I recently got a request to be able to handle ArrayList defined in TheProperties.cs.

So the SCG Developer wanted to define string in a ArrayList and wanted to display them during runtime in a combobox, like the one we do with the Enumerator, and wanted to use the selected value in the templates.

Soon I realized this need 3 purposes served

1. Display the list of strings in a combobox at runtime.
2. Know which value the end user has selected and use that in SCGTemplates.
3. Display the PropertyName at runtime.

I cannot use System.Collection.ArrayList directly as it can serve the first purpose but not the second and third at the same time, ArrayList need properties to hold the SelectedValue and PropertyName. So I extended the ArrayList and add extended properties to it.

public class ScArrayList:System.Collections.ArrayList
  private string selectedValue;

  public string SelectedValue
    get { return selectedValue; }
    set { selectedValue = value; }

  private string propertyName;
  //Display Name of the Property
  public string PropertyName
    get { return propertyName; }
    set { propertyName = value; }


Next Step would be to write a UIProperty for this ScArrayList


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ScArrayListUIProperty.ascx.cs" Inherits="ScArrayListUIProperty" %>
<td id="prop">
<asp:Label ID="lblPropertyName" runat="server" Text="PropertyName" CssClass="label2"></asp:Label></td>
<asp:DropDownList ID="ddProperty" runat="server">

As you can see a DropDownList and a Label control is added.

Here is the Codebehind file content and I ll try to comment the purpose of the codes.

public partial class ScArrayListUIProperty : ScUIPropertyBase
  protected void Page_Load(object sender, EventArgs e)


  #region ScFrameworkSpecific

  PropertyInfo propertyInfo = null;
  ScArrayList o = null;
  public ScArrayListUIProperty( )
  { }

  public ScArrayListUIProperty(PropertyInfo propertyInfo)
    //Hooking ArrayListUIProperty_OnPreGenerate to the ParentPage Event
    ParentPage.OnPreGenerate += new EventHandler(ArrayListUIProperty_OnPreGenerate);

    this.propertyInfo = propertyInfo;
    if (propertyInfo.CanRead)
      //Cast the PropertyInfo back to ScArrayList
      o = (ScArrayList)propertyInfo.GetValue(ParentPage.TheProperties, null);
      if (o != null)
        //add each item string object of the ArrayList to the DropDownList
        foreach (string item in o)
        //Assign the Label.Text with the PropertyName
        lblPropertyName.Text = o.PropertyName;


  public void ArrayListUIProperty_OnPreGenerate(object sender, EventArgs e)

    //Get the SelectedValue from the DropDownList component and set the value
    o.SelectedValue = ddProperty.SelectedValue;

    if (propertyInfo.CanWrite)
      this.propertyInfo.SetValue(ParentPage.TheProperties, o, null);



Finally need to map this ScArrayListUIProperty in the PropertyAndUIPropertyMaps.xml
by adding the following node.


Thats it we are done.

A Demo TheProperties.cs may look like this:

public class TheProperties
  public TheProperties( )

  private ScArrayList testList = new ScArrayList();
  public ScArrayList TestList
    if (testList.Count == 0)
      testList = new ScArrayList();
      testList.PropertyName = "TestList"
    return testList;
    testList = value;

and this should bring up a combobox during the runtime for you to choose an option. 

Posted on Thursday, May 24, 2007 6:43 PM | Back to top

Comments on this post: SmartCodeGenerator UIProperty for ArrayList of Strings

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Shahed Khan | Powered by: