Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

Last post 04-29-2007 5:35 PM by szmitek. 6 replies.

Sort Posts:

  • Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

    04-27-2007, 9:25 AM
    • Loading...
    • szmitek
    • Joined on 03-03-2007, 7:22 PM
    • Chotomów, Poland
    • Posts 61

    How to make conditional repeating with Repeater? I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active":

    ...

    <

    script type="text/c#" language="c#" runat="server">

    public string active

    {

    get

    {

    return "index";

    }

    }

    </script>

    ...

    <asp:Repeater runat="server" DataSourceID="AccessDataSource2"> <ItemTemplate><asp:HyperLink runat="server" NavigateUrl='<% # Eval ("file") + ".aspx" %>' Text='<%# Eval("name_pl") %>' ToolTip='<%# Eval("title_pl") %>'></asp:HyperLink></ItemTemplate><SeparatorTemplate>&nbsp;</SeparatorTemplate>

    </asp:Repeater>

    ...

    <asp:AccessDataSource id="AccessDataSource2" runat="server" datafile="~/App_Data/data.mdb" selectcommand="SELECT [file], [name_pl], [title_pl] from [pages]" />

    ...

    How to do this?

  • Re: Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

    04-27-2007, 10:48 AM
    • Loading...
    • webswapp
    • Joined on 04-05-2006, 4:08 PM
    • Vancouver, BC, Canada
    • Posts 292
    cssClass ='<%#IIF(Eval("file").ToString().Equals("string active"),"active","")%>'
    HTH,
    Phillip Williams,
    http://mcts-study-practices.com
    http://www.webswapp.com
  • Indifferent [:|] Re: Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

    04-28-2007, 2:38 PM
    • Loading...
    • szmitek
    • Joined on 03-03-2007, 7:22 PM
    • Chotomów, Poland
    • Posts 61

    "If" does not exist in curent context. Code "cssClass ='<%#IF(Eval("file").ToString().Equals(active),"active","")%>' " cause error CS0103. Full information about error on the page http://szmitek.winweb.pl/pl/links.aspx

    Code of script: 

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <script runat="server" language="c#" type="text/c#">

    public string active

    {

    get

    {

    return "links";

    }

    }

    </script>

    ...

    <

    asp:Repeater runat="server" DataSourceID="layout">

    <ItemTemplate>

    <asp:Literal runat="server" Text='<% # Eval("header") %>'></asp:Literal></ItemTemplate>

    </asp:Repeater>

    ...

    <asp:Repeater runat="server" DataSourceID="pages">

    <ItemTemplate>

    <asp:HyperLink runat="server" CssClass='<% # IF (Eval("file").ToString().Equals(active),"active","")%>'

    NavigateUrl='<% # Eval ("file") + ".aspx" %>' Text='<%# Eval("name_pl") %>' ToolTip='<%# Eval("title_pl") %>'></asp:HyperLink></ItemTemplate>

    <SeparatorTemplate>

    &nbsp;</SeparatorTemplate>

    </asp:Repeater>

    <asp:Repeater runat="server" DataSourceID="layout">

    <ItemTemplate>

    <asp:Literal runat="server" Text='<% # Eval("menu_pl1") + active + Eval("menu_pl2") %>'></asp:Literal></ItemTemplate>

    </asp:Repeater>

    ...

    <asp:AccessDataSource ID="layout" runat="server" DataFile="~/App_Data/data.mdb"

    SelectCommand="SELECT [header], [menu_pl1], [menu_pl2] from [layout]"></asp:AccessDataSource>

    <asp:AccessDataSource ID="pages" runat="server" DataFile="~/App_Data/data.mdb"

    SelectCommand="SELECT [file], [name_pl], [title_pl] from [pages]"></asp:AccessDataSource>

    How to resolve this problem?

  • Re: Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

    04-28-2007, 4:17 PM
    • Loading...
    • webswapp
    • Joined on 04-05-2006, 4:08 PM
    • Vancouver, BC, Canada
    • Posts 292

    The syntax of the function is IIF (not IF)

    http://msdn2.microsoft.com/en-us/library/27ydhh0d(VS.80).aspx

    HTH,
    Phillip Williams,
    http://mcts-study-practices.com
    http://www.webswapp.com
  • Re: Conditional repeating with Repeater. I want Repeter to add "CssClass='active'' to hyperlink when content of column "file" for curent field equals "string active"

    04-28-2007, 5:41 PM
    • Loading...
    • szmitek
    • Joined on 03-03-2007, 7:22 PM
    • Chotomów, Poland
    • Posts 61

    Is "IIF" function also in C#? There is the same problem with it. 

    Server Error in '/Kamil Szmit (szmitek)' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'IIf' does not exist in the current context

    Source Error:

    [No relevant source lines]

    Source File:    Line: 0
    // Line below was wrapped my me 
    I:\Program Files\Microsoft Visual Studio 8\Common7\IDE> "I:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output
     /R:"I:\Windows\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll"
     /R:"I:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll"
     /R:"I:\Windows\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll"
     /R:"I:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"I:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll"
     /R:"I:\Windows\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll"
     /out:"I:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\kamil szmit (szmitek)\38e65460\e81460f2\App_Web_links.aspx.a78b30ac.y04myklg.dll"
     /D:DEBUG /debug+ /optimize- /win32res:"I:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\kamil szmit (szmitek)\38e65460\e81460f2\cxq38la1.res"
     /w:4 /nowarn:1659;1699
      "I:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\kamil szmit (szmitek)\38e65460\e81460f2\App_Web_links.aspx.a78b30ac.y04myklg.0.cs"
     "I:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\kamil szmit (szmitek)\38e65460\e81460f2\App_Web_links.aspx.a78b30ac.y04myklg.1.cs"
    
    
    Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
    for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
    Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
    
    i:\Users\Administrator\Documents\My Web Sites\Kamil Szmit (szmitek)\pl\links.aspx(39,83): error CS0103: The name 'IIf' does not exist in the current context
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.312

  • Re: Conditional repeating with Repeater. I want Repeter to add &quot;CssClass='active'' to hyperlink when content of column &quot;file&quot; for curent field equals &quot;string active&quot;

    04-28-2007, 6:05 PM
    Answer
    • Loading...
    • webswapp
    • Joined on 04-05-2006, 4:08 PM
    • Vancouver, BC, Canada
    • Posts 292
    szmitek:

    Is "IIF" function also in C#? There is the same problem with it. 

    No.  for C#

    CssClass

    ='<%#Eval("FieldName").ToString().Equals("SomeValue")?"TrueEvalResult":"FalseEvalResult" %>'
    HTH,
    Phillip Williams,
    http://mcts-study-practices.com
    http://www.webswapp.com
  • Thank you!

    04-29-2007, 5:35 PM
    • Loading...
    • szmitek
    • Joined on 03-03-2007, 7:22 PM
    • Chotomów, Poland
    • Posts 61

    Thank you.

    Source:

    ...

    <

    asp:Repeater runat="server" DataSourceID="pages">

    <

    ItemTemplate>

    <

    asp:HyperLink runat="server" CssClass='<%#Eval("file").ToString().Equals(active)?"active":"" %>'

    NavigateUrl='<% # Eval ("file") + ".aspx" %>' Text='<%# Eval("name_en") %>' ToolTip='<%# Eval("title_en") %>'></asp:HyperLink></ItemTemplate>

    </

    asp:Repeater>

    ...

    <

    asp:AccessDataSource ID="pages" runat="server" DataFile="~/App_Data/data.mdb" SelectCommand="SELECT [file], [name_en], [title_en] from [pages]">

    </

    asp:AccessDataSource>

    ...

    Result: menu visible on all pages of Web site http://szmitek.winweb.pl

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter