This project is read-only.

Help me... what I doing wrong?

Topics: Developer Forum
Feb 9, 2009 at 8:07 PM
I can't get <%# TotalItems %> in *.aspx file... from its codebehind method TotalItems. What's wrong?
I've tried <%# this.TotalItems %> and many other ways, there's no errors and no results...

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrettyNewsListViewer.aspx.cs" Inherits="N2.Addons.PrettyNews.UI.PrettyNewsListViewer" MasterPageFile="~/Templates/UI/Layouts/Top+SubMenu.master" %>

<asp:Content ContentPlaceHolderID="PostContent" runat="server">
    <n2:ItemDataSource id="idsNews" runat="server" />
    _______________<%# TotalItems %>____________________
    <asp:Repeater runat="server" DataSourceID="idsNews" ID="PrettyNewsRepeater">
        <HeaderTemplate><div class="list"></HeaderTemplate>
            <div class="item listItem i<%# Container.ItemIndex %> a<%# Container.ItemIndex % 2 %>">           
                <div class="image float-left"><img src='<%# Eval("IntroImage") %>' alt='<%# Eval("Title") %>' /></div>
                <div class="abstract float-right getGoldBg">
                    <a href='<%# Eval("Url") %>'><%# Eval("Title") %></a>
                    <p><%# Eval("Introduction") %></p>
                    <div class="date"><%# ((System.DateTime)Eval("Published")).ToShortDateString()%></div>                    

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using N2;
using N2.Templates.Items;

namespace N2.Addons.PrettyNews.UI
    public partial class PrettyNewsListViewer : N2.Templates.Web.UI.TemplatePage<N2.Addons.PrettyNews.Items.PrettyNewsContainer>
        public int _TotalItems = 0;
        public int TotalItems
            get { return _TotalItems; }
            set { _TotalItems = value; }
        protected N2.Web.UI.WebControls.ItemDataSource idsNews;
        protected override void OnInit(EventArgs e)
            idsNews.Filtering += new EventHandler<N2.Collections.ItemListEventArgs>(idsNews_Filtering);           

        void idsNews_Filtering(object sender, N2.Collections.ItemListEventArgs e)
            Collections.TypeFilter.Filter(e.Items, typeof(N2.Addons.PrettyNews.Items.PrettyNewsItem));
            Collections.ItemFilter.Filter(e.Items, new Collections.PublishedFilter());
            Collections.ItemFilter.Filter(e.Items, new Collections.AccessFilter());
            this._TotalItems = e.Items.Count();
            int pNum = Request.QueryString["p"] == null ? 0 : Int32.Parse(Request.QueryString["p"].ToString());
            int thisIndex = pNum * CurrentItem.PerPageNumber;
            int perPage = CurrentItem.PerPageNumber;
            Collections.CountFilter.Filter(e.Items, thisIndex, perPage);

Feb 9, 2009 at 8:32 PM
The problem appears to be DataBind(). The easiest might be adding a label runat server and updating it on page pre render.
Feb 9, 2009 at 8:56 PM
Hmmm... why databind? How could I test it?
I don't want to deal with Repeater, I just want to get method output on page. <%# Method %>
Feb 9, 2009 at 9:04 PM
Try <%= TotalItems %> and if you have the time look up how the databind output (<%# %> works in ASP.NET
Feb 9, 2009 at 9:08 PM
Haaaa... it works, but i've tryed this. Very strange.
Feb 9, 2009 at 10:51 PM
I've discovered the <%$ Code:   %> logic... it's great.
And how does it deal with page loading perfomance/speed?