DataBinding: ‘System.String’ does not contain a property with the name ‘Value’.

I had to work a very simple implementation for a dot net page where on the dropdownlist I had to bind string values from ArrayList and Hashtable.
When the data was loaded from hash table and then from the ArrayList was the situation to got this error.
The reason behind is, while using the Hashtable, I has assigned for key and value to be populated from the hash table, this said, when I populate it from the ArrayList, the control tries to assign value and key from the object inside the ArrayList which was plain String which doesn’t have value property.
Simple remedy:
1. Assign the key and values to null on the case of the ArrayList OR
2. Wrap the string other object and provide a property of Value – I haven’t tried it, but in principle, it should work.

Here is a snippet of the code behind:

  1. protected void btnArrayList_Click(object sender, EventArgs e)
  2.         {
  3.             ArrayList list = new ArrayList();
  4.             list.Add("Name one");
  5.             list.Add("Name two");
  6.             list.Add("Name three");
  7.             list.Add("Name four");
  8.             DropDownList1.DataSource = list;
  9.             DropDownList1.DataTextField = null;
  10.             DropDownList1.DataValueField = null;
  11.             DropDownList1.DataBind();
  12.         }
  14.         protected void btnHashTable_Click(object sender, EventArgs e)
  15.         {
  16.             Hashtable table = new Hashtable();
  17.             table.Add("one", "name one");
  18.             table.Add("two", "name two");
  19.             table.Add("three", "name three");
  20.             table.Add("four", "name four");
  21.             table.Add("five", "name five");
  22.             DropDownList1.DataSource = table;
  23.             DropDownList1.DataTextField = "Value";
  24.             DropDownList1.DataValueField = "Key";
  25.             DropDownList1.DataBind();
  26.         }

Happy DataBinding.