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.

Knowing Accessibility of Methods Using Reflection

While programming, one inquiry would be to know the if the methods from the given class could be accessible or not from any object, from derived class, from assembly or from derived & assembly…
Knowing ahead for time these factors would reduce the error theater from running.
Say a class with the following definition is given:

class Person{
     private void privateMethod(){}
     public void publicMethod(){}
     protected void protectedMethod(){}
     internal void internalMehtod(){}
     public static void staticMethod(){}
     public virtual void virtualMethod(){}
     protected internal void internalProtectedMethod(){}

So, while trying to access the methods of the Person class and wanted to know accessibility – no problem..
Dot Net has provided the following methods for this specific usage under the implementation of reflection

.Name - tells the name of the method
.IsPublic - checks if the method in the class is public or not (public)
.IsStatic - checks if the method is static (static)
.IsVirtual - checks if the method is virtual (virtual)
.IsAssembly - answers if it can be accessed from assembly (internal)
.IsFamily - answers if it can be accessed from derived class (protected)
.IsFamilyOrAssembly - from derived or assebmbly (protected internal)
.IsFamilyAndAssembly - from derived and assembly 

Look @ For example and application

Server.Transfer() and Response.Redirect()

Working on my current project, I come up with a scenario to switch a visitor to a new page after some process.
Here I have an option to use either redirect() or server.transfer(). So what are the tradeoffs:

  • Redirect() would allow to navigate to other pages out of the current website unlike Transfer()
  • Redirect() needs a round-trip to client page but transfer() won’t need this which would make transfer() a bit fast

Well for my case, I am not redirecting to other page and I want it to be fast so – I have used Server.Transfer().

For questions related to page transfer refer

What is PostBack in ASP.NET

Postback in simple terms is self referal of the page. In earlier version of ASP, the form would ‘POST’ values to another page for validation or some process using the post method.
But in ASP.NET, the page which accepts the values through its form would be responsible for validating/processing the values.
More @