page variable in a repeater

Posted by carrot_programmer_3 on Stack Overflow See other posts from Stack Overflow or by carrot_programmer_3
Published on 2010-05-27T13:14:56Z Indexed on 2010/05/27 13:51 UTC
Read the original article Hit count: 180

Filed under:
|
|

Hi I'm having a bit of an issue with a asp.net repeater

I'm building a categories carousel with the dynamic categories being output by a repeater. Each item is a LinkButton control that passes an argument of the category id to the onItemClick handler.

a page variable is set by this handler to track what the selected category id is....

public String SelectedID
    {
        get
        {

            object o = this.ViewState["_SelectedID"];
            if (o == null)
                return "-1"; 
            else
                return (String)o;
        }

        set
        {
            this.ViewState["_SelectedID"] = value;
        }
    }

problem is that i cant seem to read this value while iterating through the repeater as follows...

<asp:Repeater ID="categoriesCarouselRepeater" runat="server" 
                onitemcommand="categoriesCarouselRepeater_ItemCommand">
            <ItemTemplate>
            <%#Convert.ToInt32(Eval("CategoryID")) == Convert.ToInt32(SelectedID) ? "<div class=\"selectedcategory\">":"<div>"%>
 <asp:LinkButton ID="LinkButton1" CommandName="select_category" CommandArgument='<%#Eval("CategoryID")%>' runat="server"><img src="<%#Eval("imageSource")%>" alt="category" /><br />

</div>

</ItemTemplate>

</asp:Repeater>

calling <%=SelectedID%> in the item template works but when i try the following expression the value of SelectedID returns empty..

<%#Convert.ToInt32(Eval("CategoryID")) == Convert.ToInt32(SelectedID) ? "match" : "not a match"%>

the value is being set as follows...

protected void categoriesCarouselRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

       SelectedID = e.CommandArgument);
}

Any ideas whats wrong here?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET