Hi,
data source resolving for the DDL expects that the member of the
collection/list item you look for the value is actually a property,
literally. Only public field doesn't qualify here. So if you put your code
like this:
*************
//Collection item
public class MyClass
{
public MyClass(string var1,string var2)
{
this._Var1 = var1;
this._Var2 = var2;
}
private string _Var1;
private string _Var2;
public string Var1
{
get
{
return _Var1;
}
}
public string Var2
{
get
{
return _Var2;
}
}
}
//Collection, brief for clarity
public class MyClassList : System.Collections.CollectionBase
{
public int Add(MyClass obj)
{
return this.List.Add(obj);
}
}
//Usage example:
MyClassList list=new MyClassList();
list.Add(new MyClass("The first","The second"));
list.Add(new MyClass("1st","2nd"));
DropDownList1.DataSource =list;
DropDownList1.DataValueField ="Var2";
DropDownList1.DataValueField ="Var1";
DropDownList1.DataBind();
*************
You'd have a working example.
Thanks,
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Christoph Boget" <jc*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Consider the following:
class MyClass {
public string Var1;
public string Var 2;
}
class MyClassList : System.Collections.CollectionBase {
// requisite access methods
}
Now, if I have a drop down box, can I define the the
datasource to be an instatiation of 'MyClassList' filled
with 'MyClass' objects? And set the 'DataTextField'
and 'DataValueField' properties to the 'Var1' and 'Var2'
properties of the 'MyClass' objects? If so, how?
Because I tried it and it didn't work. I think it's because
it doesn't know how to implicitely access the 'Var1' and
'Var2' properties, but that's just my guess.
thnx,
Christoph