Menu Item - Problem - Help!


A

AJ

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
 
Ad

Advertisements

S

Stan

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.
 
Ad

Advertisements

A

AJ

Hi Stan,

Thanks for the help- that worked!

AJ

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top