Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Menu Item - Problem - Help!

Reply
Thread Tools

Menu Item - Problem - Help!

 
 
AJ
Guest
Posts: n/a
 
      08-09-2008
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

 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      08-09-2008
On 9 Aug, 07:51, "AJ" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
AJ
Guest
Posts: n/a
 
      08-09-2008
Hi Stan,

Thanks for the help- that worked!

AJ

"Stan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On 9 Aug, 07:51, "AJ" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert a menu item in an existing menu. BlueFlash Python 2 08-26-2009 10:26 PM
How do I set selected Menu item in a asp:menu control? goran.strand@gmail.com ASP .Net 0 12-22-2006 08:05 AM
"Shutdown" menu item disapper from START menu......... vik Computer Support 5 08-09-2006 03:14 PM
ASP.Menu in IE6, cannot select menu item when... mwr ASP .Net Web Controls 2 06-21-2006 10:00 AM
How to do bitmap icon in front of menu-items in Java? what is the class for menu-item in Java? gino Java 12 09-01-2004 04:14 PM



Advertisments