Problem with DataList using Custom Class

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.
 
T

Tian Min Huang

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top