Problem with DataList using Custom Class

  • Thread starter Thread starter Jurjen de Groot
  • Start date Start date
J

Jurjen de Groot

I have an ArrayList with NewsItem objects wich have properties 'newsDate'
and 'newsText'

I can off course bind the ArrayList to the Datalist, but how do I procede
from there ?

In the ItemTemplate I've placed two labels wich should show the properties
of each NewsItem.

I'm trying to find out how to databind the properties of the custom NewsItem
class to these labels.



Any help is greatly appreciated.
 
Hello Jurjen,

Thanks for your post. I'd like to check the following issues:

1. Make sure that the properties newsDate and newsText are exposed with get
and/or set accessor, for example:

class NewsItem{
public string newsDate{
get {
return ...;
}
}

public string newsText{
get {
return ...;
}
}
}

2. You can declare the ItemTemplate like the following:
<ItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%#
DataBinder.Eval(ContainerDataItem,"newsDate") %>'>
</asp:TextBox>
</ItemTemplate>


In the meantime, I believe the following articles/samples are very helpful:

Data Binding Server Controls
http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatabinding.aspx

INFO: Roadmap for Web Forms Data Binding
http://support.microsoft.com/default.aspx?scid=kb;en-us;313481

DataList vs. DataGrid in ASP.NET
http://msdn.microsoft.com/msdnmag/issues/01/12/asp/default.aspx

If the problem persists, could you post some code snippet which is able to
demonstrate the problem? I will be glad to check it on my side.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Back
Top