How to retrieve items from Ilist in .net 2.0?
IList-Items Retrieval
Collapse
X
-
Hi,
I guess below example might b helpful to u..
public static Dictionary DataSourceToDic tionary(object dataSource, string valueMember, string displayMember)
{
IList list = dataSource as IList;
Dictionary listLookup = new Dictionary();
if (list != null && list.Count > 0)
{
PropertyInfo valueMemberInfo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(va lueMember);
PropertyInfo displayMemberIn fo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(di splayMember);
foreach (object item in list)
{
listLookup.Add( valueMemberInfo .GetValue(item, null).ToString( ), displayMemberIn fo.GetValue(ite m, null).ToString( ));
}
}
return listLookup;
}
Regards,
SameerComment
-
Thanks for the reply.when i try this codeOriginally posted by SameerluckyHi,
I guess below example might b helpful to u..
public static Dictionary DataSourceToDic tionary(object dataSource, string valueMember, string displayMember)
{
IList list = dataSource as IList;
Dictionary listLookup = new Dictionary();
if (list != null && list.Count > 0)
{
PropertyInfo valueMemberInfo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(va lueMember);
PropertyInfo displayMemberIn fo = dataSource.GetT ype().GetGeneri cArguments()[0].GetProperty(di splayMember);
foreach (object item in list)
{
listLookup.Add( valueMemberInfo .GetValue(item, null).ToString( ), displayMemberIn fo.GetValue(ite m, null).ToString( ));
}
}
return listLookup;
}
Regards,
Sameer
i am getting an error like this:
"Using the generic type 'System.Collect ions.Generic.Di ctionary<TKey,T Value>' requires '2' type arguments " while building
.
I am new to Dictionary,pls let me know how to make a call this function with thes 3 parameters..
Thanks in AdvanceComment
Comment