Menu Item - Problem - Help!

Discussion in 'ASP .Net Building Controls' started by AJ, Aug 9, 2008.

  1. AJ

    AJ Guest

    Hi,

    I'm trying to customize the Menu navigation control so that the the static
    items have two lines. The first line will be the text (for example "About
    Us"), and the second line will be a short description. Also, I have a method
    in my class that accepts a string and returns the description required.

    Here is what I have on the aspx file:

    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
    <DynamicItemTemplate>
    <%# Eval("Text") %><br />
    </DynamicItemTemplate>
    <StaticItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Text")
    %>'></asp:Label>
    <br />
    <asp:Label ID="Label2" runat="server"
    Text= '<%# GetDescriptionFromTitle(Eval("Text"))
    %>'></asp:Label>
    </StaticItemTemplate>
    </asp:Menu>

    As you can see above, the Static Item's second line (Label2) calls the
    GetDescriptionFromTitle method. However, the problem I'm facing is that I
    can't get it to accept the Eval("Text") as the parameter to this method.

    The errors I recieve are (they point to the aspx file):

    Error 1 The best overloaded method match for
    '_Default.GetDescriptionFromTitle(string)' has some invalid arguments
    Error 2 Argument '1': cannot convert from 'object' to 'string'

    Any idea what I'm doing wrong?

    Appreciate any help or pointers.

    Thanks,

    AJ
     
    AJ, Aug 9, 2008
    #1
    1. Advertising

  2. AJ

    Stan Guest

    On 9 Aug, 07:51, "AJ" <> wrote:
    > Hi,
    >
    > I'm trying to customize the Menu navigation control so that the the static
    > items have two lines. The first line will be the text (for example "About
    > Us"), and the second line will be a short description. Also, I have a method
    > in my class that accepts a string and returns the description required.
    >
    > Here is what I have on the aspx file:
    >
    > <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
    > <DynamicItemTemplate>
    > <%# Eval("Text") %><br />
    > </DynamicItemTemplate>
    >     <StaticItemTemplate>
    >         <asp:Label ID="Label1" runat="server" Text='<%# Eval("Text")
    > %>'></asp:Label>
    >         <br />
    >         <asp:Label ID="Label2" runat="server"
    >             Text= '<%# GetDescriptionFromTitle(Eval("Text"))
    > %>'></asp:Label>
    >     </StaticItemTemplate>
    > </asp:Menu>
    >
    > As you can see above, the Static Item's second line (Label2) calls the
    > GetDescriptionFromTitle method. However, the problem I'm facing is that I
    > can't get it to accept the Eval("Text") as the parameter to this method.
    >
    > The errors I recieve are (they point to the aspx file):
    >
    > Error 1 The best overloaded method match for
    > '_Default.GetDescriptionFromTitle(string)' has some invalid arguments
    > Error 2 Argument '1': cannot convert from 'object' to 'string'
    >
    > Any idea what I'm doing wrong?
    >
    > Appreciate any help or pointers.
    >
    > Thanks,
    >
    > AJ


    Hi

    Try this:

    Text= '<%# GetDescriptionFromTitle(Eval("Text").ToString()) %>'></
    asp:Label>

    The problem is that the Eval() function returns an object. When it is
    bound to the Text property of a Control the DataBinder does the
    conversion. In your case it is being supplied as a parameter to a
    function that expects a string object so you have to do the conversion
    in your code.
     
    Stan, Aug 9, 2008
    #2
    1. Advertising

  3. AJ

    AJ Guest

    Hi Stan,

    Thanks for the help- that worked!

    AJ

    "Stan" <> wrote in message
    news:...
    On 9 Aug, 07:51, "AJ" <> wrote:
    > Hi,
    >
    > I'm trying to customize the Menu navigation control so that the the static
    > items have two lines. The first line will be the text (for example "About
    > Us"), and the second line will be a short description. Also, I have a
    > method
    > in my class that accepts a string and returns the description required.
    >
    > Here is what I have on the aspx file:
    >
    > <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
    > <DynamicItemTemplate>
    > <%# Eval("Text") %><br />
    > </DynamicItemTemplate>
    > <StaticItemTemplate>
    > <asp:Label ID="Label1" runat="server" Text='<%# Eval("Text")
    > %>'></asp:Label>
    > <br />
    > <asp:Label ID="Label2" runat="server"
    > Text= '<%# GetDescriptionFromTitle(Eval("Text"))
    > %>'></asp:Label>
    > </StaticItemTemplate>
    > </asp:Menu>
    >
    > As you can see above, the Static Item's second line (Label2) calls the
    > GetDescriptionFromTitle method. However, the problem I'm facing is that I
    > can't get it to accept the Eval("Text") as the parameter to this method.
    >
    > The errors I recieve are (they point to the aspx file):
    >
    > Error 1 The best overloaded method match for
    > '_Default.GetDescriptionFromTitle(string)' has some invalid arguments
    > Error 2 Argument '1': cannot convert from 'object' to 'string'
    >
    > Any idea what I'm doing wrong?
    >
    > Appreciate any help or pointers.
    >
    > Thanks,
    >
    > AJ


    Hi

    Try this:

    Text= '<%# GetDescriptionFromTitle(Eval("Text").ToString()) %>'></
    asp:Label>

    The problem is that the Eval() function returns an object. When it is
    bound to the Text property of a Control the DataBinder does the
    conversion. In your case it is being supplied as a parameter to a
    function that expects a string object so you have to do the conversion
    in your code.
     
    AJ, Aug 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gino
    Replies:
    12
    Views:
    1,059
    Keith Wansbrough
    Sep 1, 2004
  2. Replies:
    0
    Views:
    1,444
  3. BlueFlash
    Replies:
    2
    Views:
    468
    John Ladasky
    Aug 26, 2009
  4. mwr

    ASP.Menu in IE6, cannot select menu item when...

    mwr, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    259
  5. SpamProof
    Replies:
    0
    Views:
    189
    SpamProof
    Jan 25, 2004
Loading...

Share This Page