This project is read-only.

How to access db data

Nov 26, 2008 at 12:39 AM
Hi everyone, seems one doesnt get too much help in here. If i have this code:

  public virtual string Interviews
        get { return (string)(GetDetail("Interviews") ?? null); }
        set { SetDetail("Interviews", value,null); }

i guess this means that in db there will be an item stored named interviews. Now my question is, how in the aspx page can i access all of this interviews items to show them? I need something like this:

<asp:Repeater ID="rptInterviews" runat="server">
                <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# Eval("Url") %>' runat="server" Text='<%# Eval("Title") %>' />

The Url and the title are not what i want, i just want the interviews cells. How can i do that? i have seen something like this:

   <n2:ItemDataSource id="idsNews" runat="server" />
 I guess it has to do with the db, but how do i make my own ItemDataSource regarding the interviews field?

Nov 26, 2008 at 7:34 AM
The property you have can mean you will have a string in the database (if you set it and save the content item).

To display it you would do something like this:

<asp:repeater... <%# Eval("Interviews") %> ...

To have a content item you can list using the itemdatasource you would need to create a class:

public class Interview : ContentItem ...

Nov 26, 2008 at 4:48 PM
Alejo, what your code shows, is that you're making a single string property Interviews. Isn't what you really want, it's to have a collection of interviews beneth some container ? If it is, than you could design your poerty something like this:

public class InterviewContainer: ContentItem {}

public class Interview: ContentItem {}

Later in your codebehind (.aspx.cs):
public partial class MyPage: N2.Web.UI.ContentPage<InterviewContainer> {
Finally, in .aspx:
<n2:ItemDataSource runat="server" id="ds">
<asp:Repeater runat="server" DataSourceID="ds">
<ItemTemplate><%# Container.DataItem %></ItemTemplate>

Ite should display all interviews beneth InterviewContainer, no matter what they really are. What do you mean under "i just want the interviews cells" ?
Nov 27, 2008 at 3:28 PM
libardo, esteewhy, tnahx for the respones. I tried what esteewhy told me, indeed im trying to create something like a container. After doing that, im having an exception, something about loading collection.

Nov 27, 2008 at 7:09 PM
Anyway, thanx a lot, im going to use a usercontrol i found, list.ascx.