Answer 2 is good.
I have a small suggestion.
ArrayList
is non generic type. Which means there is
no type safety
, i.e. in the above example
a1.Add("Test");
a1.Add(5);
will both work but it will
throw error at run time
if the required type is say either
string or int
only.
Secondly, when used with
value types
in case of non generic types there is an
overhead of boxing and unboxing
.
So, it is better to use the
Generic
counter part of
ArrayList
i.e.
List<T>
explained here
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[
^], by populating it with the values from the DB as already shown in Solution 2.
For the case shown in the question only one column is being used in the
GridView
in which case I think a
ListBox
can be lightweight control unless there is a specific requirement to use a
GridView
.
In case
GridView
is required to be used, in particular with more than one column, I think it is better to use a
DataTable
.