MenuItem.ImageUrl Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the URL to an image that is displayed next to the text in a menu item.
public:
property System::String ^ ImageUrl { System::String ^ get(); void set(System::String ^ value); };
public string ImageUrl { get; set; }
member this.ImageUrl : string with get, set
Public Property ImageUrl As String
Property Value
The URL to a custom image that is displayed next to the text of a menu item. The default value is an empty string (""), which indicates that this property is not set.
Examples
The following example demonstrates how to use the ImageUrl property to display a custom image next to the text of a menu item.
<%@ 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 runat="server">
<title>MenuItem Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Create submenu items -->
<!-- by nesting them within parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
imageurl="Images\Home.gif"
popoutimageurl="Images\Popout.jpg"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
popoutimageurl="Images\Popout.jpg"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
separatorimageurl="Images\Separator.jpg"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
separatorimageurl="Images\Separator.jpg"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
separatorimageurl="Images\Separator.jpg"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
popoutimageurl="Images\Popout.jpg"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
separatorimageurl="Images\Separator.jpg"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
separatorimageurl="Images\Separator.jpg"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
separatorimageurl="Images\Separator.jpg"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!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 runat="server">
<title>MenuItem Declarative Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Declarative Example</h3>
<!-- Use declarative syntax to create the -->
<!-- menu structure. Create submenu items -->
<!-- by nesting them within parent menu -->
<!-- items. -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Home"
imageurl="Images\Home.gif"
popoutimageurl="Images\Popout.jpg"
tooltip="Home">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
popoutimageurl="Images\Popout.jpg"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
separatorimageurl="Images\Separator.jpg"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
separatorimageurl="Images\Separator.jpg"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
separatorimageurl="Images\Separator.jpg"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Movies"
popoutimageurl="Images\Popout.jpg"
tooltip="Movies">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
separatorimageurl="Images\Separator.jpg"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
separatorimageurl="Images\Separator.jpg"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
separatorimageurl="Images\Separator.jpg"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
Remarks
Use the ImageUrl property to specify a custom image for the current menu item in the Menu control. This image is displayed next to the menu item text and can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기