views:

26

answers:

2

I am trying to create a simple menu system using repeaters. In the system I want to use a different formatting for class sub items and am trying to use an If that checks the DataBinders results and branches if its "Classes" but when I compile the code is says:

Name "Container" not declared.

On all the tutorials online and MSDN the Container.DataItem is just assumed to work so i can't find any information on it not working. Can anyone who uses databinders more than me explain this?

<asp:Repeater ID="TopNavRepeat" runat="server" DataSourceID="SqlDataSource1"  >
            <HeaderTemplate>
                <ul id="nav">
            </HeaderTemplate>
            <ItemTemplate>
                <li>
                    <asp:HiddenField ID="LinkIdField1" Value='<%# Eval("id") %>' runat="server" 
                            OnDataBinding="LinkIdField_ValueChanged" OnValueChanged="LinkIdField_ValueChanged"/>
                    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Url") %>'
                        ToolTip='<%# Eval("Description") %>'>
                    </asp:HyperLink>
                        <ul>
                        <!-- -->
                        <% If (CStr(DataBinder.Eval(Container.DataItem, "Title")) = "Classes")THEN %>
                        <asp:Repeater ID="ClassDownList" runat="server" DataSourceID="ClassDS">
                            <HeaderTemplate></HeaderTemplate>
                            <ItemTemplate>
                            <li><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>' NavigateUrl='<%# "/Class/" & helpers.urlSafe(CStr(Eval("name"))) %>'
                            ToolTip='<%# CStr(Eval("name")) & " home page" %>' /></li>
                            </ItemTemplate>
                            <FooterTemplate></FooterTemplate>
                        </asp:Repeater>
                        <% Else %>
                        <asp:Repeater ID="DropDownList" runat="server" OnLoad="ChildDataList_Init">
                            <HeaderTemplate></HeaderTemplate>
                            <ItemTemplate>
                            <li><asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("Url") %>'
                            ToolTip='<%# Eval("Description") %>' /></li>
                            </ItemTemplate>
                            <FooterTemplate></FooterTemplate>
                        </asp:Repeater>
                        <%End If %>
                        </ul>
                </li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
A: 

I'm not a VB guy, but is it because you're making an assignment, rather than a comparison?

<%# If (CStr(DataBinder.Eval(Container.DataItem, "Title")) = "Classes")THEN %>

Should it not be:

<%# If (CStr(DataBinder.Eval(Container.DataItem, "Title")) == "Classes")THEN %>
Wayne Hartman
No, in VB "=" always means *the right thing*. ;-) In other words: Assignments inside an expression are not possible.
Heinzi
A: 

i think u can't use <% If %> inside a repeater

just set .Visible=False to one of them on server side

or try (not sure if this works)

<asp:Repeater Visible='<%# (CStr(DataBinder.Eval(Container.DataItem, "Title")) = "Classes") %>'>
y34h